Debian Codegraph @

3rdparty/iaxclient/lib/gsm/src/preprocess.c

raw symbols SCIP
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 /* $Header$ */
8
9 #include <stdio.h>
10 #include <assert.h>
11
12 #include "private.h"
13
14 #include "gsm.h"
15 #include "proto.h"
16
17 /* 4.2.0 .. 4.2.3 PREPROCESSING SECTION
18 *
19 * After A-law to linear conversion (or directly from the
20 * Ato D converter) the following scaling is assumed for
21 * input to the RPE-LTP algorithm:
22 *
23 * in: 0.1.....................12
24 * S.v.v.v.v.v.v.v.v.v.v.v.v.*.*.*
25 *
26 * Where S is the sign bit, v a valid bit, and * a "don't care" bit.
27 * The original signal is called sop[..]
28 *
29 * out: 0.1................... 12
30 * S.S.v.v.v.v.v.v.v.v.v.v.v.v.0.0
31 */
32
33
34 void Gsm_Preprocess P3((S, s, so),
35 struct gsm_state * S,
36 word * s,
37 word * so ) /* [0..159] IN/OUT */
38 {
39
40 word z1 = S->z1;
41 longword L_z2 = S->L_z2;
42 word mp = S->mp;
43
44 word s1;
45
46
47 word SO;
48
49 longword ltmp; /* for ADD */
50 ulongword utmp; /* for L_ADD */
51
52 register int k = 160;
53
54 while (k--) {
55
56 /* 4.2.1 Downscaling of the input signal
57 */
58 /* SO = SASR( *s, 3 ) << 2;*/
59 SO = SASR( *s, 1 ) & ~3;
60 s++;
61
62 assert (SO >= -0x4000); /* downscaled by */
63 assert (SO <= 0x3FFC); /* previous routine. */
64
65
66 /* 4.2.2 Offset compensation
67 *
68 * This part implements a high-pass filter and requires extended
69 * arithmetic precision for the recursive part of this filter.
70 * The input of this procedure is the array so[0...159] and the
71 * output the array sof[ 0...159 ].
72 */
73 /* Compute the non-recursive part
74 */
75
76 s1 = SO - z1; /* s1 = gsm_sub( *so, z1 ); */
77 z1 = SO;
78
79 assert(s1 != MIN_WORD);
80
81 /* SJB Remark: float might be faster than the mess that follows */
82
83 /* Compute the recursive part
84 */
85
86 /* Execution of a 31 bv 16 bits multiplication
87 */
88 {
89 word msp;
90 #ifndef __GNUC__
91 word lsp;
92 #endif
93 longword L_s2;
94 longword L_temp;
95
96 L_s2 = s1;
97 L_s2 <<= 15;
98 #ifndef __GNUC__
99 msp = SASR( L_z2, 15 );
100 lsp = L_z2 & 0x7fff; /* gsm_L_sub(L_z2,(msp<<15)); */
101
102 L_s2 += GSM_MULT_R( lsp, 32735 );
103 L_temp = (longword)msp * 32735; /* GSM_L_MULT(msp,32735) >> 1;*/
104 L_z2 = GSM_L_ADD( L_temp, L_s2 );
105 /* above does L_z2 = L_z2 * 0x7fd5/0x8000 + L_s2 */
106 #else
107 L_z2 = ((long long)L_z2*32735 + 0x4000)>>15;
108 /* alternate (ansi) version of above line does slightly different rounding:
109 * L_temp = L_z2 >> 9;
110 * L_temp += L_temp >> 5;
111 * L_temp = (++L_temp) >> 1;
112 * L_z2 = L_z2 - L_temp;
113 */
114 L_z2 = GSM_L_ADD(L_z2,L_s2);
115 #endif
116 /* Compute sof[k] with rounding
117 */
118 L_temp = GSM_L_ADD( L_z2, 16384 );
119
120 /* 4.2.3 Preemphasis
121 */
122
123 msp = GSM_MULT_R( mp, -28180 );
124 mp = SASR( L_temp, 15 );
125 *so++ = GSM_ADD( mp, msp );
126 }
127 }
128
129 S->z1 = z1;
130 S->L_z2 = L_z2;
131 S->mp = mp;
132 }