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  Filename: /audio/gsm_amr/c/src/reorder.c
31 
32 ------------------------------------------------------------------------------
33  REVISION HISTORY
34 
35  Description:
36               1. Eliminated unused include file add.h.
37               2. Replaced array addressing by pointers
38               3. Eliminated math operations that unnecessary checked for
39                  saturation
40               4. Replaced loop counter with decrement loops
41 
42  Description:  Replaced "int" and/or "char" with OSCL defined types.
43 
44  Who:                       Date:
45  Description:
46 
47 ------------------------------------------------------------------------------
48 */
49 
50 
51 /*----------------------------------------------------------------------------
52 ; INCLUDES
53 ----------------------------------------------------------------------------*/
54 #include    "reorder.h"
55 
56 /*----------------------------------------------------------------------------
57 ; MACROS
58 ; [Define module specific macros here]
59 ----------------------------------------------------------------------------*/
60 
61 /*----------------------------------------------------------------------------
62 ; DEFINES
63 ; [Include all pre-processor statements here. Include conditional
64 ; compile variables also.]
65 ----------------------------------------------------------------------------*/
66 
67 /*----------------------------------------------------------------------------
68 ; LOCAL FUNCTION DEFINITIONS
69 ; [List function prototypes here]
70 ----------------------------------------------------------------------------*/
71 
72 /*----------------------------------------------------------------------------
73 ; LOCAL VARIABLE DEFINITIONS
74 ; [Variable declaration - defined here and used outside this module]
75 ----------------------------------------------------------------------------*/
76 
77 
78 /*
79 ------------------------------------------------------------------------------
80  FUNCTION NAME: Reorder_lsf
81 ------------------------------------------------------------------------------
82  INPUT AND OUTPUT DEFINITIONS
83 
84  Inputs:
85     lsf = vector of LSFs   (range: 0<=val<=0.5)(Word16)
86     min_dist = minimum required distance (Word16)
87     n = LPC order (Word16)
88     pOverflow = pointer to overflow (Flag)
89 
90  Outputs:
91     pOverflow -> 1 if the add operation called by Reorder_lsf() results in
92      overflow
93     lsf -> reordered vector of LSFs (Word16)
94 
95  Returns:
96     None
97 
98  Global Variables Used:
99     None
100 
101  Local Variables Needed:
102     None
103 
104 ------------------------------------------------------------------------------
105  FUNCTION DESCRIPTION
106 
107  This function makes sure that the LSFs are properly ordered keeps a certain
108  minimum distance between adjacent LSFs.
109 
110 ------------------------------------------------------------------------------
111  REQUIREMENTS
112 
113  None
114 
115 ------------------------------------------------------------------------------
116  REFERENCES
117 
118  [1] reorder.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
119 
120 ------------------------------------------------------------------------------
121  PSEUDO-CODE
122 
123 void Reorder_lsf (
124     Word16 *lsf,        // (i/o)     : vector of LSFs   (range: 0<=val<=0.5)
125     Word16 min_dist,    // (i)       : minimum required distance
126     Word16 n            // (i)       : LPC order
127 )
128 {
129     Word16 i;
130     Word16 lsf_min;
131 
132 // The reference ETSI code uses a global flag for Overflow. In the actual
133 // implementation a pointer to Overflow flag is passed into the function
134 // for use by the math functions add() and sub()
135 
136     lsf_min = min_dist;
137     for (i = 0; i < n; i++)
138     {
139         if (sub (lsf[i], lsf_min) < 0)
140         {
141             lsf[i] = lsf_min;
142         }
143         lsf_min = add (lsf[i], min_dist);
144     }
145 }
146 
147 ------------------------------------------------------------------------------
148  RESOURCES USED [optional]
149 
150  When the code is written for a specific target processor the
151  the resources used should be documented below.
152 
153  HEAP MEMORY USED: x bytes
154 
155  STACK MEMORY USED: x bytes
156 
157  CLOCK CYCLES: (cycle count equation for this function) + (variable
158                 used to represent cycle count for each subroutine
159                 called)
160      where: (cycle count variable) = cycle count for [subroutine
161                                      name]
162 
163 ------------------------------------------------------------------------------
164  CAUTION [optional]
165  [State any special notes, constraints or cautions for users of this function]
166 
167 ------------------------------------------------------------------------------
168 */
169 
170 /*----------------------------------------------------------------------------
171 ; FUNCTION CODE
172 ----------------------------------------------------------------------------*/
Reorder_lsf(Word16 * lsf,Word16 min_dist,Word16 n,Flag * pOverflow)173 void Reorder_lsf(
174     Word16 *lsf,        /* (i/o)    : vector of LSFs   (range: 0<=val<=0.5) */
175     Word16 min_dist,    /* (i)      : minimum required distance             */
176     Word16 n,           /* (i)      : LPC order                             */
177     Flag   *pOverflow   /* (i/o)    : Overflow flag                         */
178 )
179 {
180     Word16 i;
181     Word16 lsf_min;
182     Word16 *p_lsf = &lsf[0];
183     OSCL_UNUSED_ARG(pOverflow);
184 
185     lsf_min = min_dist;
186     for (i = 0; i < n; i++)
187     {
188         if (*(p_lsf) < lsf_min)
189         {
190             *(p_lsf++) = lsf_min;
191             lsf_min +=  min_dist;
192         }
193         else
194         {
195             lsf_min = *(p_lsf++) + min_dist;
196         }
197     }
198 }
199 
200