Initialize Tizen 2.3
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_nb / enc / src / spreproc.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: spreproc.cpp
35  Functions: subframePreProc
36
37 ------------------------------------------------------------------------------
38  MODULE DESCRIPTION
39
40
41 ------------------------------------------------------------------------------
42 */
43
44 /*----------------------------------------------------------------------------
45 ; INCLUDES
46 ----------------------------------------------------------------------------*/
47 #include "spreproc.h"
48 #include "typedef.h"
49 #include "weight_a.h"
50 #include "syn_filt.h"
51 #include "residu.h"
52 #include "oscl_mem.h"
53
54 /*----------------------------------------------------------------------------
55 ; MACROS
56 ; Define module specific macros here
57 ----------------------------------------------------------------------------*/
58
59 /*----------------------------------------------------------------------------
60 ; DEFINES
61 ; Include all pre-processor statements here. Include conditional
62 ; compile variables also.
63 ----------------------------------------------------------------------------*/
64
65 /*----------------------------------------------------------------------------
66 ; LOCAL FUNCTION DEFINITIONS
67 ; Function Prototype declaration
68 ----------------------------------------------------------------------------*/
69
70 /*----------------------------------------------------------------------------
71 ; LOCAL VARIABLE DEFINITIONS
72 ; Variable declaration - defined here and used outside this module
73 ----------------------------------------------------------------------------*/
74
75 /*
76 ------------------------------------------------------------------------------
77  FUNCTION NAME: subframePreProc
78 ------------------------------------------------------------------------------
79  INPUT AND OUTPUT DEFINITIONS
80
81  Inputs:
82     mode        -- enum Mode          -- coder mode
83     gamma1      -- const Word16 array -- spectral exp. factor 1
84     gamma1_12k2 -- const Word16 array -- spectral exp. factor 1 for EFR
85     gamma2      -- const Word16 array -- spectral exp. factor 2
86     A           -- Pointer to Word16  -- A(z) unquantized for the 4 subframes
87     Aq          -- Pointer to Word16  -- A(z)   quantized for the 4 subframes
88     speech      -- Pointer to Word16  -- speech segment
89     mem_err     -- Pointer to Word16  -- pointer to error signal
90     mem_w0      -- Pointer to Word16  -- memory of weighting filter
91     zero        -- Pointer to Word16  -- pointer to zero vector
92
93  Outputs:
94     ai_zero -- Word16 array -- history of weighted synth. filter
95     exc     -- Word16 array -- long term prediction residual
96     h1      -- Word16 array -- impulse response
97     xn      -- Word16 array -- target vector for pitch search
98     res2    -- Word16 array -- long term prediction residual
99     error   -- Word16 array -- error of LPC synthesis filter
100
101  Returns:
102     Zero
103
104  Global Variables Used:
105     None
106
107  Local Variables Needed:
108     None
109
110 ------------------------------------------------------------------------------
111  FUNCTION DESCRIPTION
112
113
114 ------------------------------------------------------------------------------
115  REQUIREMENTS
116
117  None
118
119 ------------------------------------------------------------------------------
120  REFERENCES
121
122  spreproc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
123
124 ------------------------------------------------------------------------------
125  PSEUDO-CODE
126
127
128 ------------------------------------------------------------------------------
129  CAUTION [optional]
130  [State any special notes, constraints or cautions for users of this function]
131
132 ------------------------------------------------------------------------------
133 */
134
135 void subframePreProc(
136     enum Mode mode,            /* i  : coder mode                            */
137     const Word16 gamma1[],     /* i  : spectral exp. factor 1                */
138     const Word16 gamma1_12k2[],/* i  : spectral exp. factor 1 for EFR        */
139     const Word16 gamma2[],     /* i  : spectral exp. factor 2                */
140     Word16 *A,                 /* i  : A(z) unquantized for the 4 subframes  */
141     Word16 *Aq,                /* i  : A(z)   quantized for the 4 subframes  */
142     Word16 *speech,            /* i  : speech segment                        */
143     Word16 *mem_err,           /* i  : pointer to error signal               */
144     Word16 *mem_w0,            /* i  : memory of weighting filter            */
145     Word16 *zero,              /* i  : pointer to zero vector                */
146     Word16 ai_zero[],          /* o  : history of weighted synth. filter     */
147     Word16 exc[],              /* o  : long term prediction residual         */
148     Word16 h1[],               /* o  : impulse response                      */
149     Word16 xn[],               /* o  : target vector for pitch search        */
150     Word16 res2[],             /* o  : long term prediction residual         */
151     Word16 error[]             /* o  : error of LPC synthesis filter         */
152 )
153 {
154     Word16 Ap1[MP1];              /* A(z) with spectral expansion         */
155     Word16 Ap2[MP1];              /* A(z) with spectral expansion         */
156     const Word16 *g1;             /* Pointer to correct gammma1 vector    */
157
158     /* mode specific pointer to gamma1 values */
159     if (mode == MR122 || mode == MR102)
160     {
161         g1 = gamma1_12k2;
162     }
163     else
164     {
165         g1 = gamma1;
166     }
167
168     /* Find the weighted LPC coefficients for the weighting filter. */
169     Weight_Ai(A, g1, Ap1);
170     Weight_Ai(A, gamma2, Ap2);
171
172     oscl_memcpy(ai_zero, Ap1, (M + 1)*sizeof(Word16));
173
174
175     Syn_filt(Aq, ai_zero, h1, L_SUBFR, zero, 0);
176     Syn_filt(Ap2, h1, h1, L_SUBFR, zero, 0);
177
178     /*
179      *
180      *          Find the target vector for pitch search:
181      *
182      */
183
184     /* LPC residual */
185     Residu(Aq, speech, res2, L_SUBFR);
186
187     oscl_memcpy(exc, res2, L_SUBFR*sizeof(Word16));
188
189     Syn_filt(Aq, exc, error, L_SUBFR, mem_err, 0);
190
191     Residu(Ap1, error, xn, L_SUBFR);
192
193     /* target signal xn[]*/
194     Syn_filt(Ap2, xn, xn, L_SUBFR, mem_w0, 0);
195
196     return;
197
198 }