📄 q_plsf_3.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_3.c Funtions: Vq_subvec4 Test_Vq_subvec4 Vq_subvec3 Test_Vq_subvec3 Q_plsf_3 Date: 05/18/00------------------------------------------------------------------------------ REVISION HISTORY Description: Updated template used to PV coding template. First attempt at optimizing C code. Description: Updated modules per Phase 2/3 review comments. Updated Vq_subvec3 pseudo-code to reflect the new restructured code. Description: Added setting of Overflow flag in inlined code. Description: Synchronized file with UMTS version 3.2.0. Updated coding template. Removed unnecessary include files. Description: Replaced basic_op.h with the header file of the math functions used in the file. Description: Made the following changes per comments from Phase 2/3 review: 1. Fixed typecasting issue with TI C compiler. 2. Optimized IF stament in Vq_subvec3() function. 3. Updated copyright year. Description: Removed redundancy in the Vq_subvec4 function. Description: Updated to accept new parameter, Flag *pOverflow. Description: Per review comments, added pOverflow flag description to the input/outputs section. Description: Corrected missed Overflow global variables -- changed to proper pOverflow. Description: Optimized all functions to further reduce clock cycle usage. Updated copyright year. Description: Added left shift by 1 in line 1050 of Q_plsf_3(). 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 This file contains the functions that perform the quantization of LSF parameters with first order MA prediction and split by 3 vector quantization (split-VQ).------------------------------------------------------------------------------*//*----------------------------------------------------------------------------; INCLUDES----------------------------------------------------------------------------*/#include "q_plsf.h"#include "typedef.h"#include "lsp_lsf.h"#include "reorder.h"#include "lsfwt.h"#include "oscl_mem.h"/*--------------------------------------------------------------------------*/#ifdef __cplusplusextern "C"{#endif /*---------------------------------------------------------------------------- ; MACROS ; Define module specific macros here ----------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------- ; DEFINES ; Include all pre-processor statements here. Include conditional ; compile variables also. ----------------------------------------------------------------------------*/#define PAST_RQ_INIT_SIZE 8 /*---------------------------------------------------------------------------- ; 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_3[]; extern const Word16 pred_fac_3[]; extern const Word16 dico1_lsf_3[]; extern const Word16 dico2_lsf_3[]; extern const Word16 dico3_lsf_3[]; extern const Word16 mr515_3_lsf[]; extern const Word16 mr795_1_lsf[]; extern const Word16 past_rq_init[]; /*--------------------------------------------------------------------------*/#ifdef __cplusplus}#endif/*------------------------------------------------------------------------------ FUNCTION NAME: Vq_subvec4------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs: lsf_r1 = pointer to the first LSF residual vector (Q15) (Word16) dico = pointer to the quantization codebook (Q15) (const Word16) wf1 = pointer to the first LSF weighting factor (Q13) (Word16) dico_size = size of quantization codebook (Q0) (Word16) Outputs: buffer pointed to by lsf_r1 contains the selected vector pOverflow -- pointer to Flag -- Flag set when overflow occurs Returns: index = quantization index (Q0) (Word16) 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_3.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEstatic Word16Vq_subvec4( // o: quantization index, Q0 Word16 * lsf_r1, // i: 1st LSF residual vector, Q15 Word16 * dico, // i: quantization codebook, Q15 Word16 * wf1, // i: 1st LSF weighting factors, Q13 Word16 dico_size) // i: size of quantization codebook, Q0{ Word16 i, index = 0; Word16 *p_dico, temp; Word32 dist_min, dist; dist_min = MAX_32; p_dico = dico; for (i = 0; i < dico_size; i++) { temp = sub (lsf_r1[0], *p_dico++); temp = mult (wf1[0], temp); dist = L_mult (temp, temp); temp = sub (lsf_r1[1], *p_dico++); temp = mult (wf1[1], temp); dist = L_mac (dist, temp, temp); temp = sub (lsf_r1[2], *p_dico++); temp = mult (wf1[2], temp); dist = L_mac (dist, temp, temp); temp = sub (lsf_r1[3], *p_dico++); temp = mult (wf1[3], temp); dist = L_mac (dist, temp, temp); if (L_sub (dist, dist_min) < (Word32) 0) { dist_min = dist; index = i; } } // Reading the selected vector p_dico = &dico[shl (index, 2)]; lsf_r1[0] = *p_dico++; lsf_r1[1] = *p_dico++; lsf_r1[2] = *p_dico++; lsf_r1[3] = *p_dico++; return index;}------------------------------------------------------------------------------ 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]------------------------------------------------------------------------------*/static Word16 Vq_subvec4( /* o: quantization index, Q0 */ Word16 * lsf_r1, /* i: 1st LSF residual vector, Q15 */ const Word16 * dico, /* i: quantization codebook, Q15 */ Word16 * wf1, /* i: 1st LSF weighting factors, Q13 */ Word16 dico_size, /* i: size of quantization codebook, Q0 */ Flag *pOverflow /* o : Flag set when overflow occurs */){ register Word16 i; Word16 temp; const Word16 *p_dico; Word16 index = 0; Word32 dist_min; Word32 dist; Word16 lsf_r1_0; Word16 lsf_r1_1; Word16 lsf_r1_2; Word16 lsf_r1_3; Word16 wf1_0; Word16 wf1_1; Word16 wf1_2; Word16 wf1_3; OSCL_UNUSED_ARG(pOverflow); dist_min = MAX_32; p_dico = dico; lsf_r1_0 = lsf_r1[0]; lsf_r1_1 = lsf_r1[1]; lsf_r1_2 = lsf_r1[2]; lsf_r1_3 = lsf_r1[3]; wf1_0 = wf1[0]; wf1_1 = wf1[1]; wf1_2 = wf1[2]; wf1_3 = wf1[3]; for (i = 0; i < dico_size; i++) { temp = lsf_r1_0 - (*p_dico++); temp = (Word16)((((Word32) wf1_0) * temp) >> 15); dist = ((Word32) temp) * temp; temp = lsf_r1_1 - (*p_dico++); temp = (Word16)((((Word32) wf1_1) * temp) >> 15); dist += ((Word32) temp) * temp; temp = lsf_r1_2 - (*p_dico++); temp = (Word16)((((Word32) wf1_2) * temp) >> 15); dist += ((Word32) temp) * temp; temp = lsf_r1_3 - (*p_dico++); temp = (Word16)((((Word32) wf1_3) * temp) >> 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++ = *p_dico++; *lsf_r1++ = *p_dico++; *lsf_r1++ = *p_dico++; *lsf_r1 = *p_dico++; return(index);}/****************************************************************************//*------------------------------------------------------------------------------ FUNCTION NAME: Test_Vq_subvec4------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs: lsf_r1 = pointer to the first LSF residual vector (Q15) (Word16) dico = pointer to the quantization codebook (Q15) (const Word16) wf1 = pointer to the first LSF weighting factor (Q13) (Word16) dico_size = size of quantization codebook (Q0) (Word16) Outputs: buffer pointed to by lsf_r1 contains the selected vector pOverflow -- pointer to Flag -- Flag set when overflow occurs Returns: index = quantization index (Q0) (Word16) Global Variables Used: None Local Variables Needed: None------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function calls the static function Vq_subvec4. It is used for testing purposes only------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES None------------------------------------------------------------------------------ PSEUDO-CODE CALL Vq_subvec4(lsf_r1 = lsf_r1 dico = dico wf1 = wf1 dico_size = dico_size) MODIFYING(nothing) RETURNING(index = tst_index4)------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -