Git init
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_nb / common / src / reorder.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  Filename: reorder.cpp
31
32 ------------------------------------------------------------------------------
33 */
34
35
36 /*----------------------------------------------------------------------------
37 ; INCLUDES
38 ----------------------------------------------------------------------------*/
39 #include    "reorder.h"
40
41 /*----------------------------------------------------------------------------
42 ; MACROS
43 ; [Define module specific macros here]
44 ----------------------------------------------------------------------------*/
45
46 /*----------------------------------------------------------------------------
47 ; DEFINES
48 ; [Include all pre-processor statements here. Include conditional
49 ; compile variables also.]
50 ----------------------------------------------------------------------------*/
51
52 /*----------------------------------------------------------------------------
53 ; LOCAL FUNCTION DEFINITIONS
54 ; [List function prototypes here]
55 ----------------------------------------------------------------------------*/
56
57 /*----------------------------------------------------------------------------
58 ; LOCAL VARIABLE DEFINITIONS
59 ; [Variable declaration - defined here and used outside this module]
60 ----------------------------------------------------------------------------*/
61
62
63 /*
64 ------------------------------------------------------------------------------
65  FUNCTION NAME: Reorder_lsf
66 ------------------------------------------------------------------------------
67  INPUT AND OUTPUT DEFINITIONS
68
69  Inputs:
70     lsf = vector of LSFs   (range: 0<=val<=0.5)(Word16)
71     min_dist = minimum required distance (Word16)
72     n = LPC order (Word16)
73     pOverflow = pointer to overflow (Flag)
74
75  Outputs:
76     pOverflow -> 1 if the add operation called by Reorder_lsf() results in
77      overflow
78     lsf -> reordered vector of LSFs (Word16)
79
80  Returns:
81     None
82
83  Global Variables Used:
84     None
85
86  Local Variables Needed:
87     None
88
89 ------------------------------------------------------------------------------
90  FUNCTION DESCRIPTION
91
92  This function makes sure that the LSFs are properly ordered keeps a certain
93  minimum distance between adjacent LSFs.
94
95 ------------------------------------------------------------------------------
96  REQUIREMENTS
97
98  None
99
100 ------------------------------------------------------------------------------
101  REFERENCES
102
103  [1] reorder.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
104
105 ------------------------------------------------------------------------------
106  PSEUDO-CODE
107
108 void Reorder_lsf (
109     Word16 *lsf,        // (i/o)     : vector of LSFs   (range: 0<=val<=0.5)
110     Word16 min_dist,    // (i)       : minimum required distance
111     Word16 n            // (i)       : LPC order
112 )
113 {
114     Word16 i;
115     Word16 lsf_min;
116
117 // The reference ETSI code uses a global flag for Overflow. In the actual
118 // implementation a pointer to Overflow flag is passed into the function
119 // for use by the math functions add() and sub()
120
121     lsf_min = min_dist;
122     for (i = 0; i < n; i++)
123     {
124         if (sub (lsf[i], lsf_min) < 0)
125         {
126             lsf[i] = lsf_min;
127         }
128         lsf_min = add (lsf[i], min_dist);
129     }
130 }
131
132 ------------------------------------------------------------------------------
133  CAUTION [optional]
134  [State any special notes, constraints or cautions for users of this function]
135
136 ------------------------------------------------------------------------------
137 */
138
139 /*----------------------------------------------------------------------------
140 ; FUNCTION CODE
141 ----------------------------------------------------------------------------*/
142 OSCL_EXPORT_REF void Reorder_lsf(
143     Word16 *lsf,        /* (i/o)    : vector of LSFs   (range: 0<=val<=0.5) */
144     Word16 min_dist,    /* (i)      : minimum required distance             */
145     Word16 n,           /* (i)      : LPC order                             */
146     Flag   *pOverflow   /* (i/o)    : Overflow flag                         */
147 )
148 {
149     Word16 i;
150     Word16 lsf_min;
151     Word16 *p_lsf = &lsf[0];
152     OSCL_UNUSED_ARG(pOverflow);
153
154     lsf_min = min_dist;
155     for (i = 0; i < n; i++)
156     {
157         if (*(p_lsf) < lsf_min)
158         {
159             *(p_lsf++) = lsf_min;
160             lsf_min +=  min_dist;
161         }
162         else
163         {
164             lsf_min = *(p_lsf++) + min_dist;
165         }
166     }
167 }
168