1 /*
2 * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
3 * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
4 * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
5 */
6
7 #include <stdio.h>
8 #include <assert.h>
9
10 #include "gsm610_priv.h"
11
12 /* 4.2.0 .. 4.2.3 PREPROCESSING SECTION
13 *
14 * After A-law to linear conversion (or directly from the
15 * Ato D converter) the following scaling is assumed for
16 * input to the RPE-LTP algorithm:
17 *
18 * in: 0.1.....................12
19 * S.v.v.v.v.v.v.v.v.v.v.v.v.*.*.*
20 *
21 * Where S is the sign bit, v a valid bit, and * a "don't care" bit.
22 * The original signal is called sop[..]
23 *
24 * out: 0.1................... 12
25 * S.S.v.v.v.v.v.v.v.v.v.v.v.v.0.0
26 */
27
28
Gsm_Preprocess(struct gsm_state * S,int16_t * s,int16_t * so)29 void Gsm_Preprocess (
30 struct gsm_state * S,
31 int16_t * s,
32 int16_t * so) /* [0..159] IN/OUT */
33 {
34
35 int16_t z1 = S->z1 ;
36 int32_t L_z2 = S->L_z2 ;
37 int16_t mp = S->mp ;
38
39 int16_t s1 ;
40 int32_t L_s2 ;
41
42 int32_t L_temp ;
43
44 int16_t msp, lsp ;
45 int16_t SO ;
46
47 register int k = 160 ;
48
49 while (k--)
50 {
51
52 /* 4.2.1 Downscaling of the input signal */
53 SO = arith_shift_left (SASR_W (*s, 3), 2) ;
54 s++ ;
55
56 assert (SO >= -0x4000) ; /* downscaled by */
57 assert (SO <= 0x3FFC) ; /* previous routine. */
58
59
60 /* 4.2.2 Offset compensation
61 *
62 * This part implements a high-pass filter and requires extended
63 * arithmetic precision for the recursive part of this filter.
64 * The input of this procedure is the array so[0...159] and the
65 * output the array sof[ 0...159 ].
66 */
67
68 /* Compute the non-recursive part */
69
70 s1 = SO - z1 ; /* s1 = gsm_sub (*so, z1) ; */
71 z1 = SO ;
72
73 assert (s1 != MIN_WORD) ;
74
75 /* Compute the recursive part */
76 L_s2 = s1 ;
77 L_s2 = arith_shift_left (L_s2, 15) ;
78
79 /* Execution of a 31 bv 16 bits multiplication */
80
81 msp = SASR_L (L_z2, 15) ;
82 lsp = L_z2 - arith_shift_left ((int32_t) msp, 15) ; /* gsm_L_sub (L_z2,(msp<<15)) ; */
83
84 L_s2 += GSM_MULT_R (lsp, 32735) ;
85 L_temp = (int32_t) msp * 32735 ; /* GSM_L_MULT (msp,32735) >> 1 ;*/
86 L_z2 = GSM_L_ADD (L_temp, L_s2) ;
87
88 /* Compute sof[k] with rounding */
89 L_temp = GSM_L_ADD (L_z2, 16384) ;
90
91 /* 4.2.3 Preemphasis */
92
93 msp = GSM_MULT_R (mp, -28180) ;
94 mp = SASR_L (L_temp, 15) ;
95 *so++ = GSM_ADD (mp, msp) ;
96 }
97
98 S->z1 = z1 ;
99 S->L_z2 = L_z2 ;
100 S->mp = mp ;
101 }
102