📄 q_plsf_5.cpp
字号:
/* ------------------------------------------------------------------ * Copyright (C) 2008 PacketVideo * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. * See the License for the specific language governing permissions * and limitations under the License. * ------------------------------------------------------------------- *//****************************************************************************************Portions of this file are derived from the following 3GPP standard: 3GPP TS 26.073 ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec Available from http://www.3gpp.org(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)Permission to distribute, modify and use this file under the standard licenseterms listed above has been obtained from the copyright holder.****************************************************************************************//*------------------------------------------------------------------------------ Pathname: ./audio/gsm-amr/c/src/q_plsf_5.c Funtions: Date: 02/05/2002------------------------------------------------------------------------------ REVISION HISTORY Description: Placed code in the PV standard template format. Updated to accept new parameter, Flag *pOverflow. Description: Eliminated unused include files. For Vq_subvec() 1. Eliminated math operations that unnecessary checked for saturation (number are bounded to 2^12) 2. Eliminated access to (slow) memory by using axiliar variables 3. Because this routine is looking for the minimum distance, introduced 3 check conditions inside the loop, so when the partial distance is bigger than the minimun distance, the loop is not completed and process continue with next iteration For Vq_subvec_s() 1. Eliminated math operations that unnecessary checked for saturation (number are bounded to 2^12) 2. Combined increasing and decreasing loops to avoid double accesses to the same table element 3. Eliminated access to (slow) memory by using axiliar variables 4. Because this routine is looking for the minimum distance, introduced 2 check conditions inside the loop, so when the partial distance is bigger than the minimun distance, the loop is not completed and process continue with next iteration For Q_plsf_5() 1. Eliminated math operations that unnecessary checked for saturation (number are bounded to 2^12) 2. Replaced array addressing by pointers Description: Replaced OSCL mem type functions and eliminated include files that now are chosen by OSCL definitions Description: Replaced "int" and/or "char" with OSCL defined types. Description: Added #ifdef __cplusplus around extern'ed table. Description:------------------------------------------------------------------------------ MODULE DESCRIPTION------------------------------------------------------------------------------*//*----------------------------------------------------------------------------; INCLUDES----------------------------------------------------------------------------*/#include "q_plsf.h"#include "typedef.h"#include "basic_op.h"#include "lsp_lsf.h"#include "reorder.h"#include "lsfwt.h"/*--------------------------------------------------------------------------*/#ifdef __cplusplusextern "C"{#endif /*---------------------------------------------------------------------------- ; MACROS ; Define module specific macros here ----------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------- ; DEFINES ; Include all pre-processor statements here. Include conditional ; compile variables also. ----------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------- ; LOCAL FUNCTION DEFINITIONS ; Function Prototype declaration ----------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------- ; LOCAL VARIABLE DEFINITIONS ; Variable declaration - defined here and used outside this module ----------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------- ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES ; Declare variables used in this module but defined elsewhere ----------------------------------------------------------------------------*/ /* Codebooks of LSF prediction residual */ extern const Word16 mean_lsf_5[]; extern const Word16 dico1_lsf_5[]; extern const Word16 dico2_lsf_5[]; extern const Word16 dico3_lsf_5[]; extern const Word16 dico4_lsf_5[]; extern const Word16 dico5_lsf_5[]; /*--------------------------------------------------------------------------*/#ifdef __cplusplus}#endif/*------------------------------------------------------------------------------ FUNCTION NAME: Vq_subvec------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs: lsf_r1 -- array of type Word16 -- 1st LSF residual vector, Q15 lsf_r2 -- array of type Word16 -- 2nd LSF residual vector, Q15 dico -- pointer to const Word16 -- quantization codebook, Q15 wf1 -- array of type Word16 -- 1st LSF weighting factors, Q13 wf2 -- array of type Word16 -- 2nd LSF weighting factors, Q13 dico_size -- Word16 -- size of quantization codebook, Q0 Outputs: pOverflow -- pointer to type Flag -- overflow indicator Returns: Word16 -- quantization index, Q0 Global Variables Used: None Local Variables Needed: None------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function performs the quantization of a 4-dimensional subvector.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES q_plsf_5.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODE------------------------------------------------------------------------------ RESOURCES USED [optional] When the code is written for a specific target processor the the resources used should be documented below. HEAP MEMORY USED: x bytes STACK MEMORY USED: x bytes CLOCK CYCLES: (cycle count equation for this function) + (variable used to represent cycle count for each subroutine called) where: (cycle count variable) = cycle count for [subroutine name]------------------------------------------------------------------------------ CAUTION [optional] [State any special notes, constraints or cautions for users of this function]------------------------------------------------------------------------------*//* Quantization of a 4 dimensional subvector */static Word16 Vq_subvec( /* o : quantization index, Q0 */ Word16 *lsf_r1, /* i : 1st LSF residual vector, Q15 */ Word16 *lsf_r2, /* i : 2nd LSF residual vector, Q15 */ const Word16 *dico, /* i : quantization codebook, Q15 */ Word16 *wf1, /* i : 1st LSF weighting factors Q13 */ Word16 *wf2, /* i : 2nd LSF weighting factors Q13 */ Word16 dico_size, /* i : size of quantization codebook, Q0 */ Flag *pOverflow /* o : overflow indicator */){ Word16 index = 0; /* initialization only needed to keep gcc silent */ Word16 i; Word16 temp; const Word16 *p_dico; Word32 dist_min; Word32 dist; Word16 wf1_0; Word16 wf1_1; Word16 wf2_0; Word16 wf2_1; Word32 aux1; Word32 aux2; Word32 aux3; Word32 aux4; OSCL_UNUSED_ARG(pOverflow); dist_min = MAX_32; p_dico = dico; wf1_0 = wf1[0]; wf1_1 = wf1[1]; wf2_0 = wf2[0]; wf2_1 = wf2[1]; aux1 = ((Word32) lsf_r1[0] * wf1_0); aux2 = ((Word32) lsf_r1[1] * wf1_1); aux3 = ((Word32) lsf_r2[0] * wf2_0); aux4 = ((Word32) lsf_r2[1] * wf2_1); for (i = 0; i < dico_size; i++) { temp = (aux1 - ((Word32)wf1_0 * *(p_dico++))) >> 15; dist = ((Word32)temp * temp); if (dist >= dist_min) { p_dico += 3; continue; } temp = (aux2 - ((Word32)wf1_1 * *(p_dico++))) >> 15; dist += ((Word32)temp * temp); if (dist >= dist_min) { p_dico += 2; continue; } temp = (aux3 - ((Word32)wf2_0 * *(p_dico++))) >> 15; dist += ((Word32)temp * temp); if (dist >= dist_min) { p_dico += 1; continue; } temp = (aux4 - ((Word32)wf2_1 * *(p_dico++))) >> 15; dist += ((Word32)temp * temp); if (dist < dist_min) { dist_min = dist; index = i; } } /* Reading the selected vector */ p_dico = &dico[ index<<2]; lsf_r1[0] = *p_dico++; lsf_r1[1] = *p_dico++; lsf_r2[0] = *p_dico++; lsf_r2[1] = *p_dico++; return index;}/*------------------------------------------------------------------------------ FUNCTION NAME: Vq_subvec_s------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs: lsf_r1 -- array of type Word16 -- 1st LSF residual vector, Q15 lsf_r2 -- array of type Word16 -- 2nd LSF residual vector, Q15 dico -- pointer to const Word16 -- quantization codebook, Q15 wf1 -- array of type Word16 -- 1st LSF weighting factors, Q13 wf2 -- array of type Word16 -- 2nd LSF weighting factors, Q13 dico_size -- Word16 -- size of quantization codebook, Q0 Outputs: pOverflow -- pointer to type Flag -- overflow indicator Returns: Word16 -- quantization index, Q0 Global Variables Used: None Local Variables Needed: None------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function performs the quantization of a 4-dimensional subvector.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES q_plsf_5.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -