1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
22 ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
23 Available from http://www.3gpp.org
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 ****************************************************************************************/
30 ------------------------------------------------------------------------------
34 Filename: spstproc.cpp
35 Functions: subframePostProc
37 ------------------------------------------------------------------------------
40 Subframe post processing
41 ------------------------------------------------------------------------------
44 /*----------------------------------------------------------------------------
46 ----------------------------------------------------------------------------*/
51 /*----------------------------------------------------------------------------
53 ; Define module specific macros here
54 ----------------------------------------------------------------------------*/
56 /*----------------------------------------------------------------------------
58 ; Include all pre-processor statements here. Include conditional
59 ; compile variables also.
60 ----------------------------------------------------------------------------*/
62 /*----------------------------------------------------------------------------
63 ; LOCAL FUNCTION DEFINITIONS
64 ; Function Prototype declaration
65 ----------------------------------------------------------------------------*/
67 /*----------------------------------------------------------------------------
68 ; LOCAL VARIABLE DEFINITIONS
69 ; Variable declaration - defined here and used outside this module
70 ----------------------------------------------------------------------------*/
73 ------------------------------------------------------------------------------
74 FUNCTION NAME: subframePostProc
75 ------------------------------------------------------------------------------
76 INPUT AND OUTPUT DEFINITIONS
80 speech -- Pointer to Word16 -- speech segment
81 mode -- enum Mode -- coder mode
82 i_subfr -- Word16 -- Subframe nr
83 gain_pit -- Word16 -- Pitch gain Q14
84 gain_code -- Word16 -- Decoded innovation gain
85 Aq -- Pointer to Word16 -- A(z) quantized for the 4 subframes
86 synth -- Word16 Array -- Local synthesis
87 xn -- Word16 Array -- Target vector for pitch search
88 code -- Word16 Array -- Fixed codebook exitation
89 y1 -- Word16 Array -- Filtered adaptive exitation
90 y2 -- Word16 Array -- Filtered fixed codebook excitation
91 mem_syn -- Pointer to Word16 -- memory of synthesis filter
94 mem_syn -- Pointer to Word16 -- memory of synthesis filter
95 mem_err -- Pointer to Word16 -- pointer to error signal
96 mem_w0 -- Pointer to Word16 -- memory of weighting filter
97 exc -- Pointer to Word16 -- long term prediction residual
98 sharp -- Pointer to Word16 -- pitch sharpening value
99 pOverflow -- Pointer to Flag -- overflow indicator
104 Global Variables Used:
107 Local Variables Needed:
110 ------------------------------------------------------------------------------
114 ------------------------------------------------------------------------------
119 ------------------------------------------------------------------------------
122 spstproc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
124 ------------------------------------------------------------------------------
128 ------------------------------------------------------------------------------
130 [State any special notes, constraints or cautions for users of this function]
132 ------------------------------------------------------------------------------
135 void subframePostProc(
136 Word16 *speech, /* i : speech segment */
137 enum Mode mode, /* i : coder mode */
138 Word16 i_subfr, /* i : Subframe nr */
139 Word16 gain_pit, /* i : Pitch gain Q14 */
140 Word16 gain_code, /* i : Decoded innovation gain */
141 Word16 *Aq, /* i : A(z) quantized for the 4 subframes */
142 Word16 synth[], /* i : Local snthesis */
143 Word16 xn[], /* i : Target vector for pitch search */
144 Word16 code[], /* i : Fixed codebook exitation */
145 Word16 y1[], /* i : Filtered adaptive exitation */
146 Word16 y2[], /* i : Filtered fixed codebook excitation */
147 Word16 *mem_syn, /* i/o : memory of synthesis filter */
148 Word16 *mem_err, /* o : pointer to error signal */
149 Word16 *mem_w0, /* o : memory of weighting filter */
150 Word16 *exc, /* o : long term prediction residual */
151 Word16 *sharp, /* o : pitch sharpening value */
152 Flag *pOverflow /* o : overflow indicator */
166 OSCL_UNUSED_ARG(pOverflow);
172 pitch_fac = gain_pit;
178 pitch_fac = gain_pit >> 1;
181 /*------------------------------------------------------------*
182 * - Update pitch sharpening "sharp" with quantized gain_pit *
183 *------------------------------------------------------------*/
185 if (gain_pit < SHARPMAX)
194 /*------------------------------------------------------*
195 * - Find the total excitation *
196 * - find synthesis speech corresponding to exc[] *
197 * - update filters memories for finding the target *
198 * vector in the next subframe *
199 * (update error[-m..-1] and mem_w_err[]) *
200 *------------------------------------------------------*/
202 p_exc = &exc[ i_subfr];
205 for (i = L_SUBFR >> 1; i != 0 ; i--)
207 /* exc[i] = gain_pit*exc[i] + gain_code*code[i]; */
211 * ---------------------------------
223 * sum<<tempShift Q16 Q16
224 * result -> exc Q0 Q0
226 L_temp = ((Word32) * (p_exc++) * pitch_fac) << 1;
227 L_temp2 = ((Word32) * (p_exc--) * pitch_fac) << 1;
228 L_temp += ((Word32) * (p_code++) * gain_code) << 1;
229 L_temp2 += ((Word32) * (p_code++) * gain_code) << 1;
230 L_temp <<= tempShift;
231 L_temp2 <<= tempShift;
232 *(p_exc++) = (Word16)((L_temp + 0x08000L) >> 16);
233 *(p_exc++) = (Word16)((L_temp2 + 0x08000L) >> 16);
245 for (i = L_SUBFR - M, j = 0; i < L_SUBFR; i++, j++)
247 mem_err[j] = speech[i_subfr + i] - synth[i_subfr + i];
251 * ---------------------------------
255 * shifted prod. Q16 Q16
262 * shifted prod. Q16 Q16
264 * mem_w0,xn,sum Q0 Q0
267 L_temp = ((Word32)y1[i] * gain_pit);
268 temp = (Word16)(L_temp >> 14);
270 L_temp = ((Word32)y2[i] * gain_code);
271 temp += (Word16)(L_temp >> kShift);
273 mem_w0[j] = xn[i] - temp;