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/****************************************************************************************
19Portions 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)
26Permission to distribute, modify and use this file under the standard license
27terms listed above has been obtained from the copyright holder.
28****************************************************************************************/
29/*
30------------------------------------------------------------------------------
31
32
33
34 Pathname: ./audio/gsm-amr/c/src/ol_ltp.c
35 Funtions: ol_ltp
36
37     Date: 04/18/2000
38
39------------------------------------------------------------------------------
40 REVISION HISTORY
41
42 Description: Adding pOverflow to the functions to remove global variables.
43              These changes are needed for the EPOC releases. Cleaned up code.
44              Updated template.
45
46 Description:  Replaced "int" and/or "char" with OSCL defined types.
47
48 Description:
49
50------------------------------------------------------------------------------
51*/
52
53/*----------------------------------------------------------------------------
54; INCLUDES
55----------------------------------------------------------------------------*/
56#include "ol_ltp.h"
57#include "cnst.h"
58#include "pitch_ol.h"
59#include "p_ol_wgh.h"
60
61/*----------------------------------------------------------------------------
62; MACROS
63; Define module specific macros here
64----------------------------------------------------------------------------*/
65
66/*----------------------------------------------------------------------------
67; DEFINES
68; Include all pre-processor statements here. Include conditional
69; compile variables also.
70----------------------------------------------------------------------------*/
71
72/*----------------------------------------------------------------------------
73; LOCAL FUNCTION DEFINITIONS
74; Function Prototype declaration
75----------------------------------------------------------------------------*/
76
77/*----------------------------------------------------------------------------
78; LOCAL VARIABLE DEFINITIONS
79; Variable declaration - defined here and used outside this module
80----------------------------------------------------------------------------*/
81
82/*
83------------------------------------------------------------------------------
84 FUNCTION NAME: ol_ltp
85------------------------------------------------------------------------------
86 INPUT AND OUTPUT DEFINITIONS
87
88 Inputs:
89    st = pointer to pitchOLWghtState structure
90    vadSt = pointer to a vadState structure
91    mode = coder mode (Mode)
92    wsp = pointer to buffer of signal used to compute the Open loop pitch
93    T_op = pointer to open loop pitch lag
94    old_lags = pointer to history with old stored Cl lags (Word16)
95    ol_gain_flg = pointer to OL gain flag (Word16)
96    idx = 16 bit value specifies the frame index
97    dtx = Data of type 'Flag' used for dtx. Use dtx=1, do not use dtx=0
98    pOverflow = pointer to Overflow indicator (Flag)
99
100 Outputs:
101    pOverflow -> 1 if processing this funvction results in satuaration
102
103 Returns:
104    Zero
105
106 Global Variables Used:
107    None
108
109 Local Variables Needed:
110    None
111
112------------------------------------------------------------------------------
113 FUNCTION DESCRIPTION
114
115 This function computes the open loop pitch lag.
116
117------------------------------------------------------------------------------
118 REQUIREMENTS
119
120 None
121
122------------------------------------------------------------------------------
123 REFERENCES
124
125 ol_ltp.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
126
127------------------------------------------------------------------------------
128 PSEUDO-CODE
129
130int ol_ltp(
131    pitchOLWghtState *st, // i/o : State struct
132    vadState *vadSt,      // i/o : VAD state struct
133    enum Mode mode,       // i   : coder mode
134    Word16 wsp[],         // i   : signal used to compute the OL pitch, Q0
135                          //       uses signal[-pit_max] to signal[-1]
136    Word16 *T_op,         // o   : open loop pitch lag,                 Q0
137    Word16 old_lags[],    // i   : history with old stored Cl lags
138    Word16 ol_gain_flg[], // i   : OL gain flag
139    Word16 idx,           // i   : index
140    Flag dtx              // i   : dtx flag; use dtx=1, do not use dtx=0
141    )
142{
143   if (sub ((Word16)mode, (Word16)MR102) != 0 )
144   {
145      ol_gain_flg[0] = 0;
146      ol_gain_flg[1] = 0;
147   }
148
149   if (sub ((Word16)mode, (Word16)MR475) == 0 || sub ((Word16)mode, (Word16)MR515) == 0 )
150   {
151      *T_op = Pitch_ol(vadSt, mode, wsp, PIT_MIN, PIT_MAX, L_FRAME, idx, dtx);
152   }
153   else
154   {
155      if ( sub ((Word16)mode, (Word16)MR795) <= 0 )
156      {
157         *T_op = Pitch_ol(vadSt, mode, wsp, PIT_MIN, PIT_MAX, L_FRAME_BY2,
158                          idx, dtx);
159      }
160      else if ( sub ((Word16)mode, (Word16)MR102) == 0 )
161      {
162         *T_op = Pitch_ol_wgh(st, vadSt, wsp, PIT_MIN, PIT_MAX, L_FRAME_BY2,
163                              old_lags, ol_gain_flg, idx, dtx);
164      }
165      else
166      {
167         *T_op = Pitch_ol(vadSt, mode, wsp, PIT_MIN_MR122, PIT_MAX,
168                          L_FRAME_BY2, idx, dtx);
169      }
170   }
171   return 0;
172}
173
174------------------------------------------------------------------------------
175 RESOURCES USED [optional]
176
177 When the code is written for a specific target processor the
178 the resources used should be documented below.
179
180 HEAP MEMORY USED: x bytes
181
182 STACK MEMORY USED: x bytes
183
184 CLOCK CYCLES: (cycle count equation for this function) + (variable
185                used to represent cycle count for each subroutine
186                called)
187     where: (cycle count variable) = cycle count for [subroutine
188                                     name]
189
190------------------------------------------------------------------------------
191 CAUTION [optional]
192 [State any special notes, constraints or cautions for users of this function]
193
194------------------------------------------------------------------------------
195*/
196
197
198/*----------------------------------------------------------------------------
199; FUNCTION CODE
200----------------------------------------------------------------------------*/
201void ol_ltp(
202    pitchOLWghtState *st, /* i/o : State struct                            */
203    vadState *vadSt,      /* i/o : VAD state struct                        */
204    enum Mode mode,       /* i   : coder mode                              */
205    Word16 wsp[],         /* i   : signal used to compute the OL pitch, Q0 */
206    /*       uses signal[-pit_max] to signal[-1]     */
207    Word16 *T_op,         /* o   : open loop pitch lag,                 Q0 */
208    Word16 old_lags[],    /* i   : history with old stored Cl lags         */
209    Word16 ol_gain_flg[], /* i   : OL gain flag                            */
210    Word16 idx,           /* i   : index                                   */
211    Flag dtx,             /* i   : dtx flag; use dtx=1, do not use dtx=0   */
212    Flag *pOverflow       /* i/o : overflow indicator                      */
213)
214{
215    if ((mode != MR102))
216    {
217        ol_gain_flg[0] = 0;
218        ol_gain_flg[1] = 0;
219    }
220
221    if ((mode == MR475) || (mode == MR515))
222    {
223        *T_op = Pitch_ol(vadSt, mode, wsp, PIT_MIN, PIT_MAX, L_FRAME, idx, dtx,
224                         pOverflow);
225    }
226    else
227    {
228        if (mode <= MR795)
229        {
230            *T_op = Pitch_ol(vadSt, mode, wsp, PIT_MIN, PIT_MAX, L_FRAME_BY2,
231                             idx, dtx, pOverflow);
232        }
233        else if (mode == MR102)
234        {
235            *T_op = Pitch_ol_wgh(st, vadSt, wsp, PIT_MIN, PIT_MAX, L_FRAME_BY2,
236                                 old_lags, ol_gain_flg, idx, dtx, pOverflow);
237        }
238        else
239        {
240            *T_op = Pitch_ol(vadSt, mode, wsp, PIT_MIN_MR122, PIT_MAX,
241                             L_FRAME_BY2, idx, dtx, pOverflow);
242        }
243    }
244
245}
246
247