1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 /**************************************************************************************** 19 Portions of this file are derived from the following 3GPP standard: 20 21 3GPP TS 26.073 22 ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec 23 Available from http://www.3gpp.org 24 25 (C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) 26 Permission to distribute, modify and use this file under the standard license 27 terms listed above has been obtained from the copyright holder. 28 ****************************************************************************************/ 29 /* 30 31 Filename: lflg_upd.cpp 32 Functions: LTP_flag_update 33 34 ------------------------------------------------------------------------------ 35 MODULE DESCRIPTION 36 37 LTP_flag update for AMR VAD option 2 38 ------------------------------------------------------------------------------ 39 */ 40 41 /*---------------------------------------------------------------------------- 42 ; INCLUDES 43 ----------------------------------------------------------------------------*/ 44 #include "typedef.h" 45 #include "cnst.h" 46 #include "l_extract.h" 47 #include "mpy_32_16.h" 48 49 #include "vad2.h" 50 #include "mode.h" 51 52 /*---------------------------------------------------------------------------- 53 ; MACROS 54 ; Define module specific macros here 55 ----------------------------------------------------------------------------*/ 56 57 /*---------------------------------------------------------------------------- 58 ; DEFINES 59 ; Include all pre-processor statements here. Include conditional 60 ; compile variables also. 61 ----------------------------------------------------------------------------*/ 62 63 /*---------------------------------------------------------------------------- 64 ; LOCAL FUNCTION DEFINITIONS 65 ; Function Prototype declaration 66 ----------------------------------------------------------------------------*/ 67 68 /*---------------------------------------------------------------------------- 69 ; LOCAL VARIABLE DEFINITIONS 70 ; Variable declaration - defined here and used outside this module 71 ----------------------------------------------------------------------------*/ 72 73 74 /* 75 ------------------------------------------------------------------------------ 76 FUNCTION NAME: 77 ------------------------------------------------------------------------------ 78 INPUT AND OUTPUT DEFINITIONS 79 80 Inputs: 81 st -- Pointer to vadState2 82 mode -- Word16 -- AMR mode 83 84 Outputs: 85 st -- Pointer to vadState2 86 pOverflow -- Pointer to Flag -- overflow indicator 87 88 Returns: 89 None 90 91 Global Variables Used: 92 None 93 94 Local Variables Needed: 95 None 96 97 ------------------------------------------------------------------------------ 98 FUNCTION DESCRIPTION 99 100 LTP_flag update for AMR VAD option 2 101 102 103 PURPOSE: 104 Set LTP_flag if the LTP gain > LTP_THRESHOLD, where the value of 105 LTP_THRESHOLD depends on the LTP analysis window length. 106 107 INPUTS: 108 109 mode 110 AMR mode 111 vadState->L_R0 112 LTP energy 113 vadState->L_Rmax 114 LTP maximum autocorrelation 115 OUTPUTS: 116 117 vadState->LTP_flag 118 Set if LTP gain > LTP_THRESHOLD 119 120 RETURN VALUE: 121 122 none 123 124 125 ------------------------------------------------------------------------------ 126 REQUIREMENTS 127 128 None 129 130 ------------------------------------------------------------------------------ 131 REFERENCES 132 133 lflg_upd.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 134 135 ------------------------------------------------------------------------------ 136 PSEUDO-CODE 137 138 139 ------------------------------------------------------------------------------ 140 CAUTION [optional] 141 [State any special notes, constraints or cautions for users of this function] 142 143 ------------------------------------------------------------------------------ 144 */ 145 146 void LTP_flag_update( 147 vadState2 * st, 148 Word16 mode, 149 Flag *pOverflow) 150 { 151 Word16 thresh; 152 Word16 hi1; 153 Word16 lo1; 154 Word32 Ltmp; 155 156 if ((mode == MR475) || (mode == MR515)) 157 { 158 thresh = 18022; /* (Word16)(32768.0*0.55); */ 159 } 160 else if (mode == MR102) 161 { 162 thresh = 19660; /* (Word16)(32768.0*0.60); */ 163 } 164 else 165 { 166 thresh = 21299; /* (Word16)(32768.0*0.65); */ 167 } 168 169 L_Extract(st->L_R0, &hi1, &lo1, pOverflow); 170 171 Ltmp = Mpy_32_16(hi1, lo1, thresh, pOverflow); 172 173 if (st->L_Rmax > Ltmp) 174 { 175 st->LTP_flag = TRUE; 176 } 177 else 178 { 179 st->LTP_flag = FALSE; 180 } 181 182 return; 183 } 184