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_lag6.cpp
37 ------------------------------------------------------------------------------
38 INPUT AND OUTPUT DEFINITIONS
41 index -- Word16 -- received pitch index
42 pit_min -- Word16 -- minimum pitch lag
43 pit_max -- Word16 -- maximum pitch lag
44 i_subfr -- Word16 -- subframe flag
45 T0 -- Pointer to type Word16 -- integer part of pitch lag
49 T0 -- Pointer to type Word16 -- integer part of pitch lag
50 T0_frac -- Pointer to type Word16 -- fractional part of pitch lag
51 pOverflow -- Pointer to type Flag -- Flag set when overflow occurs
56 Global Variables Used:
59 Local Variables Needed:
62 ------------------------------------------------------------------------------
65 PURPOSE: Decoding of fractional pitch lag with 1/6 resolution.
66 Extract the integer and fraction parts of the pitch lag from
67 the received adaptive codebook index.
69 See "Enc_lag6.c" for more details about the encoding procedure.
71 The fractional lag in 1st and 3rd subframes is encoded with 9 bits
72 while that in 2nd and 4th subframes is relatively encoded with 6 bits.
73 Note that in relative encoding only 61 values are used. If the
74 decoder receives 61, 62, or 63 as the relative pitch index, it means
75 that a transmission error occurred. In this case, the pitch lag from
76 previous subframe (actually from previous frame) is used.
78 ------------------------------------------------------------------------------
83 ------------------------------------------------------------------------------
86 dec_lag6.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
88 ------------------------------------------------------------------------------
93 ------------------------------------------------------------------------------
97 /*----------------------------------------------------------------------------
99 ----------------------------------------------------------------------------*/
100 #include "dec_lag6.h"
102 #include "basic_op.h"
104 /*----------------------------------------------------------------------------
106 ; Define module specific macros here
107 ----------------------------------------------------------------------------*/
110 /*----------------------------------------------------------------------------
112 ; Include all pre-processor statements here. Include conditional
113 ; compile variables also.
114 ----------------------------------------------------------------------------*/
116 /*----------------------------------------------------------------------------
117 ; LOCAL FUNCTION DEFINITIONS
118 ; Function Prototype declaration
119 ----------------------------------------------------------------------------*/
122 /*----------------------------------------------------------------------------
123 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
124 ; Variable declaration - defined here and used outside this module
125 ----------------------------------------------------------------------------*/
127 /*----------------------------------------------------------------------------
128 ; EXTERNAL FUNCTION REFERENCES
129 ; Declare functions defined elsewhere and referenced in this module
130 ----------------------------------------------------------------------------*/
132 /*----------------------------------------------------------------------------
133 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
134 ; Declare variables used in this module but defined elsewhere
135 ----------------------------------------------------------------------------*/
137 /*----------------------------------------------------------------------------
139 ----------------------------------------------------------------------------*/
142 Word16 index, /* input : received pitch index */
143 Word16 pit_min, /* input : minimum pitch lag */
144 Word16 pit_max, /* input : maximum pitch lag */
145 Word16 i_subfr, /* input : subframe flag */
146 Word16 *T0, /* in/out: integer part of pitch lag */
147 Word16 *T0_frac, /* output: fractional part of pitch lag */
148 Flag *pOverflow /* o : Flag set when overflow occurs */
156 if (i_subfr == 0) /* if 1st or 3rd subframe */
160 /* T0 = (index+5)/6 + 17 */
162 i = ((Word32) i * 5462) >> 15;
174 /* *T0_frac = index - T0*6 + 105 */
189 else /* second or fourth subframe */
191 /* find T0_min and T0_max for 2nd (or 4th) subframe */
195 if (T0_min < pit_min)
202 if (T0_max > pit_max)
209 /* i = (index+5)/6 - 1 */
212 i = ((Word32) i * 5462) >> 15;