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 Pathname: ./audio/gsm-amr/c/src/spreproc.c 35 Functions: subframePreProc 36 37 Date: 02/06/2002 38 39 ------------------------------------------------------------------------------ 40 REVISION HISTORY 41 42 Description: Updated template used to PV coding template. 43 Eliminated unnecessary use of the sub() function. 44 45 Description: 46 1. Replaced copy() and for-loop with more efficient memcpy(). 47 2. Eliminated unused include file copy.h. 48 49 Description: Replaced OSCL mem type functions and eliminated include 50 files that now are chosen by OSCL definitions 51 52 Description: Replaced "int" and/or "char" with OSCL defined types. 53 54 Description: 55 56 ------------------------------------------------------------------------------ 57 MODULE DESCRIPTION 58 59 60 ------------------------------------------------------------------------------ 61 */ 62 63 /*---------------------------------------------------------------------------- 64 ; INCLUDES 65 ----------------------------------------------------------------------------*/ 66 #include <string.h> 67 68 #include "spreproc.h" 69 #include "typedef.h" 70 #include "weight_a.h" 71 #include "syn_filt.h" 72 #include "residu.h" 73 74 /*---------------------------------------------------------------------------- 75 ; MACROS 76 ; Define module specific macros here 77 ----------------------------------------------------------------------------*/ 78 79 /*---------------------------------------------------------------------------- 80 ; DEFINES 81 ; Include all pre-processor statements here. Include conditional 82 ; compile variables also. 83 ----------------------------------------------------------------------------*/ 84 85 /*---------------------------------------------------------------------------- 86 ; LOCAL FUNCTION DEFINITIONS 87 ; Function Prototype declaration 88 ----------------------------------------------------------------------------*/ 89 90 /*---------------------------------------------------------------------------- 91 ; LOCAL VARIABLE DEFINITIONS 92 ; Variable declaration - defined here and used outside this module 93 ----------------------------------------------------------------------------*/ 94 95 /* 96 ------------------------------------------------------------------------------ 97 FUNCTION NAME: subframePreProc 98 ------------------------------------------------------------------------------ 99 INPUT AND OUTPUT DEFINITIONS 100 101 Inputs: 102 mode -- enum Mode -- coder mode 103 gamma1 -- const Word16 array -- spectral exp. factor 1 104 gamma1_12k2 -- const Word16 array -- spectral exp. factor 1 for EFR 105 gamma2 -- const Word16 array -- spectral exp. factor 2 106 A -- Pointer to Word16 -- A(z) unquantized for the 4 subframes 107 Aq -- Pointer to Word16 -- A(z) quantized for the 4 subframes 108 speech -- Pointer to Word16 -- speech segment 109 mem_err -- Pointer to Word16 -- pointer to error signal 110 mem_w0 -- Pointer to Word16 -- memory of weighting filter 111 zero -- Pointer to Word16 -- pointer to zero vector 112 113 Outputs: 114 ai_zero -- Word16 array -- history of weighted synth. filter 115 exc -- Word16 array -- long term prediction residual 116 h1 -- Word16 array -- impulse response 117 xn -- Word16 array -- target vector for pitch search 118 res2 -- Word16 array -- long term prediction residual 119 error -- Word16 array -- error of LPC synthesis filter 120 121 Returns: 122 Zero 123 124 Global Variables Used: 125 None 126 127 Local Variables Needed: 128 None 129 130 ------------------------------------------------------------------------------ 131 FUNCTION DESCRIPTION 132 133 134 ------------------------------------------------------------------------------ 135 REQUIREMENTS 136 137 None 138 139 ------------------------------------------------------------------------------ 140 REFERENCES 141 142 spreproc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001 143 144 ------------------------------------------------------------------------------ 145 PSEUDO-CODE 146 147 148 ------------------------------------------------------------------------------ 149 RESOURCES USED [optional] 150 151 When the code is written for a specific target processor the 152 the resources used should be documented below. 153 154 HEAP MEMORY USED: x bytes 155 156 STACK MEMORY USED: x bytes 157 158 CLOCK CYCLES: (cycle count equation for this function) + (variable 159 used to represent cycle count for each subroutine 160 called) 161 where: (cycle count variable) = cycle count for [subroutine 162 name] 163 164 ------------------------------------------------------------------------------ 165 CAUTION [optional] 166 [State any special notes, constraints or cautions for users of this function] 167 168 ------------------------------------------------------------------------------ 169 */ 170 171 void subframePreProc( 172 enum Mode mode, /* i : coder mode */ 173 const Word16 gamma1[], /* i : spectral exp. factor 1 */ 174 const Word16 gamma1_12k2[],/* i : spectral exp. factor 1 for EFR */ 175 const Word16 gamma2[], /* i : spectral exp. factor 2 */ 176 Word16 *A, /* i : A(z) unquantized for the 4 subframes */ 177 Word16 *Aq, /* i : A(z) quantized for the 4 subframes */ 178 Word16 *speech, /* i : speech segment */ 179 Word16 *mem_err, /* i : pointer to error signal */ 180 Word16 *mem_w0, /* i : memory of weighting filter */ 181 Word16 *zero, /* i : pointer to zero vector */ 182 Word16 ai_zero[], /* o : history of weighted synth. filter */ 183 Word16 exc[], /* o : long term prediction residual */ 184 Word16 h1[], /* o : impulse response */ 185 Word16 xn[], /* o : target vector for pitch search */ 186 Word16 res2[], /* o : long term prediction residual */ 187 Word16 error[] /* o : error of LPC synthesis filter */ 188 ) 189 { 190 Word16 Ap1[MP1]; /* A(z) with spectral expansion */ 191 Word16 Ap2[MP1]; /* A(z) with spectral expansion */ 192 const Word16 *g1; /* Pointer to correct gammma1 vector */ 193 194 /* mode specific pointer to gamma1 values */ 195 if (mode == MR122 || mode == MR102) 196 { 197 g1 = gamma1_12k2; 198 } 199 else 200 { 201 g1 = gamma1; 202 } 203 204 /* Find the weighted LPC coefficients for the weighting filter. */ 205 Weight_Ai(A, g1, Ap1); 206 Weight_Ai(A, gamma2, Ap2); 207 208 memcpy(ai_zero, Ap1, (M + 1)*sizeof(Word16)); 209 210 211 Syn_filt(Aq, ai_zero, h1, L_SUBFR, zero, 0); 212 Syn_filt(Ap2, h1, h1, L_SUBFR, zero, 0); 213 214 /* 215 * 216 * Find the target vector for pitch search: 217 * 218 */ 219 220 /* LPC residual */ 221 Residu(Aq, speech, res2, L_SUBFR); 222 223 memcpy(exc, res2, L_SUBFR*sizeof(Word16)); 224 225 Syn_filt(Aq, exc, error, L_SUBFR, mem_err, 0); 226 227 Residu(Ap1, error, xn, L_SUBFR); 228 229 /* target signal xn[]*/ 230 Syn_filt(Ap2, xn, xn, L_SUBFR, mem_w0, 0); 231 232 return; 233 234 } 235