annotate libgsmfr2/preprocess.c @ 295:962861d46ccf

gsmfr-encode-r: add -h option for encoder homing
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Apr 2024 20:05:58 +0000
parents bd2271cb95d4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
269
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This C source file has been adapted from TU-Berlin libgsm source,
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * original notice follows:
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 *
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 */
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdint.h>
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <assert.h>
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "tw_gsmfr.h"
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "typedef.h"
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "ed_state.h"
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include "ed_internal.h"
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 /* 4.2.0 .. 4.2.3 PREPROCESSING SECTION
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 *
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 * After A-law to linear conversion (or directly from the
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 * Ato D converter) the following scaling is assumed for
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 * input to the RPE-LTP algorithm:
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 *
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 * in: 0.1.....................12
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 * S.v.v.v.v.v.v.v.v.v.v.v.v.*.*.*
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 *
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 * Where S is the sign bit, v a valid bit, and * a "don't care" bit.
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 * The original signal is called sop[..]
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 *
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 * out: 0.1................... 12
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 * S.S.v.v.v.v.v.v.v.v.v.v.v.v.0.0
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 */
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 void Gsm_Preprocess (
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 struct gsmfr_0610_state * S,
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 const word * s,
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 word * so ) /* [0..159] IN/OUT */
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 {
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 word z1 = S->z1;
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 longword L_z2 = S->L_z2;
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 word mp = S->mp;
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 word s1;
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 longword L_s2;
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 longword L_temp;
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 word msp, lsp;
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 word SO;
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 longword ltmp; /* for ADD */
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 ulongword utmp; /* for L_ADD */
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 register int k = 160;
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 while (k--) {
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 /* 4.2.1 Downscaling of the input signal
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 */
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 SO = SASR( *s, 3 ) << 2;
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 s++;
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 assert (SO >= -0x4000); /* downscaled by */
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 assert (SO <= 0x3FFC); /* previous routine. */
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 /* 4.2.2 Offset compensation
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 *
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 * This part implements a high-pass filter and requires extended
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 * arithmetic precision for the recursive part of this filter.
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 * The input of this procedure is the array so[0...159] and the
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 * output the array sof[ 0...159 ].
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 */
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 /* Compute the non-recursive part
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 */
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 s1 = SO - z1; /* s1 = gsm_sub( *so, z1 ); */
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 z1 = SO;
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 assert(s1 != MIN_WORD);
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 /* Compute the recursive part
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 */
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 L_s2 = s1;
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 L_s2 <<= 15;
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 /* Execution of a 31 bv 16 bits multiplication
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 */
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 msp = SASR( L_z2, 15 );
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 lsp = L_z2-((longword)msp<<15); /* gsm_L_sub(L_z2,(msp<<15)); */
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 L_s2 += GSM_MULT_R( lsp, 32735 );
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 L_temp = (longword)msp * 32735; /* GSM_L_MULT(msp,32735) >> 1;*/
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 L_z2 = GSM_L_ADD( L_temp, L_s2 );
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 /* Compute sof[k] with rounding
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 */
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 L_temp = GSM_L_ADD( L_z2, 16384 );
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 /* 4.2.3 Preemphasis
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 */
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 msp = GSM_MULT_R( mp, -28180 );
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 mp = SASR( L_temp, 15 );
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 *so++ = GSM_ADD( mp, msp );
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 }
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 S->z1 = z1;
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 S->L_z2 = L_z2;
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 S->mp = mp;
bd2271cb95d4 libgsmfr2: integrate preprocess.c from libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 }