Initialize Tizen 2.3
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_nb / enc / src / ol_ltp.cpp
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
32
33
34  Filename: ol_ltp.cpp
35  Functions: ol_ltp
36
37 */
38
39 /*----------------------------------------------------------------------------
40 ; INCLUDES
41 ----------------------------------------------------------------------------*/
42 #include "ol_ltp.h"
43 #include "cnst.h"
44 #include "pitch_ol.h"
45 #include "p_ol_wgh.h"
46
47 /*----------------------------------------------------------------------------
48 ; MACROS
49 ; Define module specific macros here
50 ----------------------------------------------------------------------------*/
51
52 /*----------------------------------------------------------------------------
53 ; DEFINES
54 ; Include all pre-processor statements here. Include conditional
55 ; compile variables also.
56 ----------------------------------------------------------------------------*/
57
58 /*----------------------------------------------------------------------------
59 ; LOCAL FUNCTION DEFINITIONS
60 ; Function Prototype declaration
61 ----------------------------------------------------------------------------*/
62
63 /*----------------------------------------------------------------------------
64 ; LOCAL VARIABLE DEFINITIONS
65 ; Variable declaration - defined here and used outside this module
66 ----------------------------------------------------------------------------*/
67
68 /*
69 ------------------------------------------------------------------------------
70  FUNCTION NAME: ol_ltp
71 ------------------------------------------------------------------------------
72  INPUT AND OUTPUT DEFINITIONS
73
74  Inputs:
75     st = pointer to pitchOLWghtState structure
76     vadSt = pointer to a vadState structure
77     mode = coder mode (Mode)
78     wsp = pointer to buffer of signal used to compute the Open loop pitch
79     T_op = pointer to open loop pitch lag
80     old_lags = pointer to history with old stored Cl lags (Word16)
81     ol_gain_flg = pointer to OL gain flag (Word16)
82     idx = 16 bit value specifies the frame index
83     dtx = Data of type 'Flag' used for dtx. Use dtx=1, do not use dtx=0
84     pOverflow = pointer to Overflow indicator (Flag)
85
86  Outputs:
87     pOverflow -> 1 if processing this funvction results in satuaration
88
89  Returns:
90     Zero
91
92  Global Variables Used:
93     None
94
95  Local Variables Needed:
96     None
97
98 ------------------------------------------------------------------------------
99  FUNCTION DESCRIPTION
100
101  This function computes the open loop pitch lag.
102
103 ------------------------------------------------------------------------------
104  REQUIREMENTS
105
106  None
107
108 ------------------------------------------------------------------------------
109  REFERENCES
110
111  ol_ltp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
112
113 ------------------------------------------------------------------------------
114  PSEUDO-CODE
115
116 int ol_ltp(
117     pitchOLWghtState *st, // i/o : State struct
118     vadState *vadSt,      // i/o : VAD state struct
119     enum Mode mode,       // i   : coder mode
120     Word16 wsp[],         // i   : signal used to compute the OL pitch, Q0
121                           //       uses signal[-pit_max] to signal[-1]
122     Word16 *T_op,         // o   : open loop pitch lag,                 Q0
123     Word16 old_lags[],    // i   : history with old stored Cl lags
124     Word16 ol_gain_flg[], // i   : OL gain flag
125     Word16 idx,           // i   : index
126     Flag dtx              // i   : dtx flag; use dtx=1, do not use dtx=0
127     )
128 {
129    if (sub ((Word16)mode, (Word16)MR102) != 0 )
130    {
131       ol_gain_flg[0] = 0;
132       ol_gain_flg[1] = 0;
133    }
134
135    if (sub ((Word16)mode, (Word16)MR475) == 0 || sub ((Word16)mode, (Word16)MR515) == 0 )
136    {
137       *T_op = Pitch_ol(vadSt, mode, wsp, PIT_MIN, PIT_MAX, L_FRAME, idx, dtx);
138    }
139    else
140    {
141       if ( sub ((Word16)mode, (Word16)MR795) <= 0 )
142       {
143          *T_op = Pitch_ol(vadSt, mode, wsp, PIT_MIN, PIT_MAX, L_FRAME_BY2,
144                           idx, dtx);
145       }
146       else if ( sub ((Word16)mode, (Word16)MR102) == 0 )
147       {
148          *T_op = Pitch_ol_wgh(st, vadSt, wsp, PIT_MIN, PIT_MAX, L_FRAME_BY2,
149                               old_lags, ol_gain_flg, idx, dtx);
150       }
151       else
152       {
153          *T_op = Pitch_ol(vadSt, mode, wsp, PIT_MIN_MR122, PIT_MAX,
154                           L_FRAME_BY2, idx, dtx);
155       }
156    }
157    return 0;
158 }
159
160 ------------------------------------------------------------------------------
161  CAUTION [optional]
162  [State any special notes, constraints or cautions for users of this function]
163
164 ------------------------------------------------------------------------------
165 */
166
167
168 /*----------------------------------------------------------------------------
169 ; FUNCTION CODE
170 ----------------------------------------------------------------------------*/
171 void ol_ltp(
172     pitchOLWghtState *st, /* i/o : State struct                            */
173     vadState *vadSt,      /* i/o : VAD state struct                        */
174     enum Mode mode,       /* i   : coder mode                              */
175     Word16 wsp[],         /* i   : signal used to compute the OL pitch, Q0 */
176     /*       uses signal[-pit_max] to signal[-1]     */
177     Word16 *T_op,         /* o   : open loop pitch lag,                 Q0 */
178     Word16 old_lags[],    /* i   : history with old stored Cl lags         */
179     Word16 ol_gain_flg[], /* i   : OL gain flag                            */
180     Word16 idx,           /* i   : index                                   */
181     Flag dtx,             /* i   : dtx flag; use dtx=1, do not use dtx=0   */
182     Flag *pOverflow       /* i/o : overflow indicator                      */
183 )
184 {
185     if ((mode != MR102))
186     {
187         ol_gain_flg[0] = 0;
188         ol_gain_flg[1] = 0;
189     }
190
191     if ((mode == MR475) || (mode == MR515))
192     {
193         *T_op = Pitch_ol(vadSt, mode, wsp, PIT_MIN, PIT_MAX, L_FRAME, idx, dtx,
194                          pOverflow);
195     }
196     else
197     {
198         if (mode <= MR795)
199         {
200             *T_op = Pitch_ol(vadSt, mode, wsp, PIT_MIN, PIT_MAX, L_FRAME_BY2,
201                              idx, dtx, pOverflow);
202         }
203         else if (mode == MR102)
204         {
205             *T_op = Pitch_ol_wgh(st, vadSt, wsp, PIT_MIN, PIT_MAX, L_FRAME_BY2,
206                                  old_lags, ol_gain_flg, idx, dtx, pOverflow);
207         }
208         else
209         {
210             *T_op = Pitch_ol(vadSt, mode, wsp, PIT_MIN_MR122, PIT_MAX,
211                              L_FRAME_BY2, idx, dtx, pOverflow);
212         }
213     }
214
215 }
216