FreeCalypso > hg > gsm-codec-lib
comparison libgsmhr1/sp_dec.c @ 603:27df1cef042c
libgsmhr1: put aToRc() only in dec_func.c
This function was originally static in sp_dec.c, but now it is needed
both in sp_dec.c and in dec_func.c shared decoder+encoder functions.
Solution: give it intermodule linkage, and let it reside in dec_func.c
only.
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Thu, 04 Dec 2025 19:05:38 +0000 |
| parents | c7c03231002d |
| children |
comparison
equal
deleted
inserted
replaced
| 602:72cdae602d6e | 603:27df1cef042c |
|---|---|
| 100 Shortword pswDirectFormCoefOut[]); | 100 Shortword pswDirectFormCoefOut[]); |
| 101 | 101 |
| 102 static Shortword lagDecode(Shortword swDeltaLag, Shortword *pswLastLag, | 102 static Shortword lagDecode(Shortword swDeltaLag, Shortword *pswLastLag, |
| 103 Shortword subfrm); | 103 Shortword subfrm); |
| 104 | 104 |
| 105 static short aToRc(Shortword swAshift, Shortword pswAin[], | |
| 106 Shortword pswRc[]); | |
| 107 | |
| 108 static Shortword agcGain(Shortword pswStateCurr[], | 105 static Shortword agcGain(Shortword pswStateCurr[], |
| 109 struct NormSw snsInSigEnergy, | 106 struct NormSw snsInSigEnergy, |
| 110 Shortword swEngyRShft); | 107 Shortword swEngyRShft); |
| 111 | 108 |
| 112 static void lookupVq(Shortword pswVqCodeWds[], Shortword pswRCOut[]); | 109 static void lookupVq(Shortword pswVqCodeWds[], Shortword pswRCOut[]); |
| 148 #define AFSHIFT 2 /* number of right shifts to be | 145 #define AFSHIFT 2 /* number of right shifts to be |
| 149 * applied to the autocorrelation | 146 * applied to the autocorrelation |
| 150 * sequence in aFlatRcDp */ | 147 * sequence in aFlatRcDp */ |
| 151 | 148 |
| 152 #define PCM_MASK 0xfff8 /* 16 to 13 bit linear PCM mask */ | 149 #define PCM_MASK 0xfff8 /* 16 to 13 bit linear PCM mask */ |
| 153 | |
| 154 /*************************************************************************** | |
| 155 * | |
| 156 * FUNCTION NAME: aToRc | |
| 157 * | |
| 158 * PURPOSE: | |
| 159 * | |
| 160 * This subroutine computes a vector of reflection coefficients, given | |
| 161 * an input vector of direct form LPC filter coefficients. | |
| 162 * | |
| 163 * INPUTS: | |
| 164 * | |
| 165 * NP | |
| 166 * order of the LPC filter (global constant) | |
| 167 * | |
| 168 * swAshift | |
| 169 * The number of right shifts applied externally | |
| 170 * to the direct form filter coefficients. | |
| 171 * | |
| 172 * pswAin[0:NP-1] | |
| 173 * The input vector of direct form LPC filter | |
| 174 * coefficients. | |
| 175 * | |
| 176 * OUTPUTS: | |
| 177 * | |
| 178 * pswRc[0:NP-1] | |
| 179 * Array containing the reflection coefficients. | |
| 180 * | |
| 181 * RETURN VALUE: | |
| 182 * | |
| 183 * siUnstableFlt | |
| 184 * If stable reflection coefficients 0, 1 if unstable. | |
| 185 * | |
| 186 * | |
| 187 * DESCRIPTION: | |
| 188 * | |
| 189 * This function performs the conversion from direct form | |
| 190 * coefficients to reflection coefficients. It is used in a_sst() | |
| 191 * and interpolateCheck(). In a_sst() reflection coefficients used | |
| 192 * as a transitional data format. aToRc() is used for this | |
| 193 * conversion. | |
| 194 * | |
| 195 * When performing interpolation, a stability check must be | |
| 196 * performed. interpolateCheck() does this by calling aToRc(). | |
| 197 * | |
| 198 * First coefficients are shifted down by iAshift. NP, the filter | |
| 199 * order is 10. The a's and rc's each have NP elements in them. An | |
| 200 * elaborate algorithm description can be found on page 443, of | |
| 201 * "Digital Processing of Speech Signals" by L.R. Rabiner and R.W. | |
| 202 * Schafer; Prentice-Hall; Englewood Cliffs, NJ (USA). 1978. | |
| 203 * | |
| 204 * REFERENCES: Sub_Clause 4.1.6, and 4.2.3 of GSM Recomendation 06.20 | |
| 205 * | |
| 206 * KEYWORDS: reflectioncoefficients, parcors, conversion, atorc, ks, as | |
| 207 * KEYWORDS: parcorcoefficients, lpc, flat, vectorquantization | |
| 208 * | |
| 209 *************************************************************************/ | |
| 210 | |
| 211 static short aToRc(Shortword swAshift, Shortword pswAin[], | |
| 212 Shortword pswRc[]) | |
| 213 { | |
| 214 | |
| 215 /*_________________________________________________________________________ | |
| 216 | | | |
| 217 | Constants | | |
| 218 |_________________________________________________________________________| | |
| 219 */ | |
| 220 | |
| 221 /*_________________________________________________________________________ | |
| 222 | | | |
| 223 | Automatic Variables | | |
| 224 |_________________________________________________________________________| | |
| 225 */ | |
| 226 | |
| 227 Shortword pswTmpSpace[NP], | |
| 228 pswASpace[NP], | |
| 229 swNormShift, | |
| 230 swActShift, | |
| 231 swNormProd, | |
| 232 swRcOverE, | |
| 233 swDiv, | |
| 234 *pswSwap, | |
| 235 *pswTmp, | |
| 236 *pswA; | |
| 237 | |
| 238 Longword L_temp; | |
| 239 | |
| 240 short int siUnstableFlt, | |
| 241 i, | |
| 242 j; /* Loop control variables */ | |
| 243 | |
| 244 /*_________________________________________________________________________ | |
| 245 | | | |
| 246 | Executable Code | | |
| 247 |_________________________________________________________________________| | |
| 248 */ | |
| 249 | |
| 250 /* Initialize starting addresses for temporary buffers */ | |
| 251 /*-----------------------------------------------------*/ | |
| 252 | |
| 253 pswA = pswASpace; | |
| 254 pswTmp = pswTmpSpace; | |
| 255 | |
| 256 /* Copy the direct form filter coefficients to a temporary array */ | |
| 257 /*---------------------------------------------------------------*/ | |
| 258 | |
| 259 for (i = 0; i < NP; i++) | |
| 260 { | |
| 261 pswA[i] = pswAin[i]; | |
| 262 } | |
| 263 | |
| 264 /* Initialize the flag for filter stability check */ | |
| 265 /*------------------------------------------------*/ | |
| 266 | |
| 267 siUnstableFlt = 0; | |
| 268 | |
| 269 /* Start computation of the reflection coefficients, Rc[9],...,Rc[1] */ | |
| 270 /*-------------------------------------------------------------------*/ | |
| 271 | |
| 272 for (i = NP - 1; i >= 1; i--) | |
| 273 { | |
| 274 | |
| 275 pswRc[i] = shl(pswA[i], swAshift); /* write Rc[i] to output array */ | |
| 276 | |
| 277 /* Check the stability of i-th reflection coefficient */ | |
| 278 /*----------------------------------------------------*/ | |
| 279 | |
| 280 siUnstableFlt = siUnstableFlt | isSwLimit(pswRc[i]); | |
| 281 | |
| 282 /* Precompute intermediate variables for needed for the computation */ | |
| 283 /* of direct form filter of order i-1 */ | |
| 284 /*------------------------------------------------------------------*/ | |
| 285 | |
| 286 if (sub(pswRc[i], SW_MIN) == 0) | |
| 287 { | |
| 288 siUnstableFlt = 1; | |
| 289 swRcOverE = 0; | |
| 290 swDiv = 0; | |
| 291 swActShift = 2; | |
| 292 } | |
| 293 else | |
| 294 { | |
| 295 L_temp = LW_MAX; /* Load ~1.0 into accum */ | |
| 296 L_temp = L_msu(L_temp, pswRc[i], pswRc[i]); /* 1.-Rc[i]*Rc[i] */ | |
| 297 swNormShift = norm_l(L_temp); | |
| 298 L_temp = L_shl(L_temp, swNormShift); | |
| 299 swNormProd = extract_h(L_temp); | |
| 300 swActShift = add(2, swNormShift); | |
| 301 swDiv = divide_s(0x2000, swNormProd); | |
| 302 swRcOverE = mult_r(pswRc[i], swDiv); | |
| 303 } | |
| 304 /* Check stability */ | |
| 305 /*---------------------*/ | |
| 306 siUnstableFlt = siUnstableFlt | isSwLimit(swRcOverE); | |
| 307 | |
| 308 /* Compute direct form filter coefficients corresponding to */ | |
| 309 /* a direct form filter of order i-1 */ | |
| 310 /*----------------------------------------------------------*/ | |
| 311 | |
| 312 for (j = 0; j <= i - 1; j++) | |
| 313 { | |
| 314 L_temp = L_mult(pswA[j], swDiv); | |
| 315 L_temp = L_msu(L_temp, pswA[i - j - 1], swRcOverE); | |
| 316 L_temp = L_shl(L_temp, swActShift); | |
| 317 pswTmp[j] = round(L_temp); | |
| 318 siUnstableFlt = siUnstableFlt | isSwLimit(pswTmp[j]); | |
| 319 } | |
| 320 | |
| 321 /* Swap swA and swTmp buffers */ | |
| 322 /*----------------------------*/ | |
| 323 | |
| 324 pswSwap = pswA; | |
| 325 pswA = pswTmp; | |
| 326 pswTmp = pswSwap; | |
| 327 } | |
| 328 | |
| 329 /* Compute reflection coefficient Rc[0] */ | |
| 330 /*--------------------------------------*/ | |
| 331 | |
| 332 pswRc[0] = shl(pswA[0], swAshift); /* write Rc[0] to output array */ | |
| 333 | |
| 334 /* Check the stability of 0-th reflection coefficient */ | |
| 335 /*----------------------------------------------------*/ | |
| 336 | |
| 337 siUnstableFlt = siUnstableFlt | isSwLimit(pswRc[0]); | |
| 338 | |
| 339 return (siUnstableFlt); | |
| 340 } | |
| 341 | 150 |
| 342 /*************************************************************************** | 151 /*************************************************************************** |
| 343 * | 152 * |
| 344 * FUNCTION NAME: a_sst | 153 * FUNCTION NAME: a_sst |
| 345 * | 154 * |
