comparison libgsmfr2/preprocess.c @ 269:bd2271cb95d4

libgsmfr2: integrate preprocess.c from libgsm
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Apr 2024 01:58:35 +0000
parents
children
comparison
equal deleted inserted replaced
268:0cfb7c95cce2 269:bd2271cb95d4
1 /*
2 * This C source file has been adapted from TU-Berlin libgsm source,
3 * original notice follows:
4 *
5 * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
6 * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
7 * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
8 */
9
10 #include <stdint.h>
11 #include <assert.h>
12 #include "tw_gsmfr.h"
13 #include "typedef.h"
14 #include "ed_state.h"
15 #include "ed_internal.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 void Gsm_Preprocess (
34 struct gsmfr_0610_state * S,
35 const word * s,
36 word * so ) /* [0..159] IN/OUT */
37 {
38
39 word z1 = S->z1;
40 longword L_z2 = S->L_z2;
41 word mp = S->mp;
42
43 word s1;
44 longword L_s2;
45
46 longword L_temp;
47
48 word msp, lsp;
49 word SO;
50
51 longword ltmp; /* for ADD */
52 ulongword utmp; /* for L_ADD */
53
54 register int k = 160;
55
56 while (k--) {
57
58 /* 4.2.1 Downscaling of the input signal
59 */
60 SO = SASR( *s, 3 ) << 2;
61 s++;
62
63 assert (SO >= -0x4000); /* downscaled by */
64 assert (SO <= 0x3FFC); /* previous routine. */
65
66
67 /* 4.2.2 Offset compensation
68 *
69 * This part implements a high-pass filter and requires extended
70 * arithmetic precision for the recursive part of this filter.
71 * The input of this procedure is the array so[0...159] and the
72 * output the array sof[ 0...159 ].
73 */
74 /* Compute the non-recursive part
75 */
76
77 s1 = SO - z1; /* s1 = gsm_sub( *so, z1 ); */
78 z1 = SO;
79
80 assert(s1 != MIN_WORD);
81
82 /* Compute the recursive part
83 */
84 L_s2 = s1;
85 L_s2 <<= 15;
86
87 /* Execution of a 31 bv 16 bits multiplication
88 */
89
90 msp = SASR( L_z2, 15 );
91 lsp = L_z2-((longword)msp<<15); /* gsm_L_sub(L_z2,(msp<<15)); */
92
93 L_s2 += GSM_MULT_R( lsp, 32735 );
94 L_temp = (longword)msp * 32735; /* GSM_L_MULT(msp,32735) >> 1;*/
95 L_z2 = GSM_L_ADD( L_temp, L_s2 );
96
97 /* Compute sof[k] with rounding
98 */
99 L_temp = GSM_L_ADD( L_z2, 16384 );
100
101 /* 4.2.3 Preemphasis
102 */
103
104 msp = GSM_MULT_R( mp, -28180 );
105 mp = SASR( L_temp, 15 );
106 *so++ = GSM_ADD( mp, msp );
107 }
108
109 S->z1 = z1;
110 S->L_z2 = L_z2;
111 S->mp = mp;
112 }