1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
22 ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
23 Available from http://www.3gpp.org
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 ****************************************************************************************/
30 ------------------------------------------------------------------------------
34 Filename: dec_lag3.cpp
37 ------------------------------------------------------------------------------
38 INPUT AND OUTPUT DEFINITIONS
41 index -- Word16 -- received pitch index
42 t0_min -- Word16 -- minimum of search range
43 t0_max -- Word16 -- maximum of search range
44 i_subfr -- Word16 -- subframe flag
45 T0_prev -- Word16 -- integer pitch delay of last subframe
46 used in 2nd and 4th subframes
47 flag4 -- Word16 -- flag for encoding with 4 bits
51 T0 -- Pointer to type Word16 -- integer part of pitch lag
52 T0_frac -- Pointer to type Word16 -- fractional part of pitch lag
53 pOverflow -- Pointer to type Flag -- Flag set when overflow occurs
58 Global Variables Used:
61 Local Variables Needed:
66 ------------------------------------------------------------------------------
69 PURPOSE: Decoding of fractional pitch lag with 1/3 resolution.
70 Extract the integer and fraction parts of the pitch lag from
71 the received adaptive codebook index.
73 See "Enc_lag3.c" for more details about the encoding procedure.
75 The fractional lag in 1st and 3rd subframes is encoded with 8 bits
76 while that in 2nd and 4th subframes is relatively encoded with 4, 5
77 and 6 bits depending on the mode.
79 ------------------------------------------------------------------------------
84 ------------------------------------------------------------------------------
87 dec_lag3.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
89 ------------------------------------------------------------------------------
94 ------------------------------------------------------------------------------
98 /*----------------------------------------------------------------------------
100 ----------------------------------------------------------------------------*/
101 #include "dec_lag3.h"
103 #include "basic_op.h"
105 /*----------------------------------------------------------------------------
107 ; Define module specific macros here
108 ----------------------------------------------------------------------------*/
111 /*----------------------------------------------------------------------------
113 ; Include all pre-processor statements here. Include conditional
114 ; compile variables also.
115 ----------------------------------------------------------------------------*/
117 /*----------------------------------------------------------------------------
118 ; LOCAL FUNCTION DEFINITIONS
119 ; Function Prototype declaration
120 ----------------------------------------------------------------------------*/
123 /*----------------------------------------------------------------------------
124 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
125 ; Variable declaration - defined here and used outside this module
126 ----------------------------------------------------------------------------*/
128 /*----------------------------------------------------------------------------
129 ; EXTERNAL FUNCTION REFERENCES
130 ; Declare functions defined elsewhere and referenced in this module
131 ----------------------------------------------------------------------------*/
133 /*----------------------------------------------------------------------------
134 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
135 ; Declare variables used in this module but defined elsewhere
136 ----------------------------------------------------------------------------*/
138 /*----------------------------------------------------------------------------
140 ----------------------------------------------------------------------------*/
142 void Dec_lag3(Word16 index, /* i : received pitch index */
143 Word16 t0_min, /* i : minimum of search range */
144 Word16 t0_max, /* i : maximum of search range */
145 Word16 i_subfr, /* i : subframe flag */
146 Word16 T0_prev, /* i : integer pitch delay of last subframe
147 used in 2nd and 4th subframes */
148 Word16 * T0, /* o : integer part of pitch lag */
149 Word16 * T0_frac, /* o : fractional part of pitch lag */
150 Word16 flag4, /* i : flag for encoding with 4 bits */
151 Flag *pOverflow /* o : Flag set when overflow occurs */
157 if (i_subfr == 0) /* if 1st or 3rd subframe */
182 *T0_frac = tmp_lag + 58;
193 { /* 2nd or 4th subframe */
198 /* 'normal' decoding: either with 5 or 6 bit resolution */
202 i = ((Word32) i * 10923) >> 15;
214 *T0_frac = tmp_lag - i;
219 /* decoding with 4 bit resolution */
231 tmp_lag = t0_min + 5;
234 i = t0_max - tmp_lag;
238 tmp_lag = t0_max - 4;
251 /* 4 >= index < 12 */
255 i = ((Word32) i * 10923) >> 15;
266 *T0_frac = tmp_lag - i;
280 } /* end if (decoding with 4 bit resolution) */