/src/libsndfile/src/GSM610/preprocess.c
Line | Count | Source |
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 | | |
29 | | void Gsm_Preprocess ( |
30 | | struct gsm_state * S, |
31 | | int16_t * s, |
32 | | int16_t * so) /* [0..159] IN/OUT */ |
33 | 0 | { |
34 | |
|
35 | 0 | int16_t z1 = S->z1 ; |
36 | 0 | int32_t L_z2 = S->L_z2 ; |
37 | 0 | int16_t mp = S->mp ; |
38 | |
|
39 | 0 | int16_t s1 ; |
40 | 0 | int32_t L_s2 ; |
41 | |
|
42 | 0 | int32_t L_temp ; |
43 | |
|
44 | 0 | int16_t msp, lsp ; |
45 | 0 | int16_t SO ; |
46 | |
|
47 | 0 | register int k = 160 ; |
48 | |
|
49 | 0 | while (k--) |
50 | 0 | { |
51 | | |
52 | | /* 4.2.1 Downscaling of the input signal */ |
53 | 0 | SO = arith_shift_left (SASR_W (*s, 3), 2) ; |
54 | 0 | s++ ; |
55 | |
|
56 | 0 | assert (SO >= -0x4000) ; /* downscaled by */ |
57 | 0 | 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 | 0 | s1 = SO - z1 ; /* s1 = gsm_sub (*so, z1) ; */ |
71 | 0 | z1 = SO ; |
72 | |
|
73 | 0 | assert (s1 != MIN_WORD) ; |
74 | | |
75 | | /* Compute the recursive part */ |
76 | 0 | L_s2 = s1 ; |
77 | 0 | L_s2 = arith_shift_left (L_s2, 15) ; |
78 | | |
79 | | /* Execution of a 31 bv 16 bits multiplication */ |
80 | |
|
81 | 0 | msp = SASR_L (L_z2, 15) ; |
82 | 0 | lsp = L_z2 - arith_shift_left ((int32_t) msp, 15) ; /* gsm_L_sub (L_z2,(msp<<15)) ; */ |
83 | |
|
84 | 0 | L_s2 += GSM_MULT_R (lsp, 32735) ; |
85 | 0 | L_temp = (int32_t) msp * 32735 ; /* GSM_L_MULT (msp,32735) >> 1 ;*/ |
86 | 0 | L_z2 = GSM_L_ADD (L_temp, L_s2) ; |
87 | | |
88 | | /* Compute sof[k] with rounding */ |
89 | 0 | L_temp = GSM_L_ADD (L_z2, 16384) ; |
90 | | |
91 | | /* 4.2.3 Preemphasis */ |
92 | |
|
93 | 0 | msp = GSM_MULT_R (mp, -28180) ; |
94 | 0 | mp = SASR_L (L_temp, 15) ; |
95 | 0 | *so++ = GSM_ADD (mp, msp) ; |
96 | 0 | } |
97 | |
|
98 | 0 | S->z1 = z1 ; |
99 | 0 | S->L_z2 = L_z2 ; |
100 | 0 | S->mp = mp ; |
101 | 0 | } |