FreeCalypso > hg > gsm-codec-lib
comparison libgsmefr/pre_proc.c @ 84:3ea19a9aa2a1
libgsmefr: pre_proc.c compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 26 Nov 2022 07:30:53 +0000 |
parents | 49dd1ac8e75b |
children |
comparison
equal
deleted
inserted
replaced
83:33714b36841a | 84:3ea19a9aa2a1 |
---|---|
8 * - 2nd order high pass filtering with cut off frequency at 80 Hz. | 8 * - 2nd order high pass filtering with cut off frequency at 80 Hz. |
9 * - Divide input by two. | 9 * - Divide input by two. |
10 * | 10 * |
11 *************************************************************************/ | 11 *************************************************************************/ |
12 | 12 |
13 #include "gsm_efr.h" | |
13 #include "typedef.h" | 14 #include "typedef.h" |
15 #include "namespace.h" | |
14 #include "basic_op.h" | 16 #include "basic_op.h" |
15 #include "oper_32b.h" | 17 #include "oper_32b.h" |
16 #include "count.h" | 18 #include "no_count.h" |
19 #include "sig_proc.h" | |
20 #include "cnst.h" | |
21 #include "enc_state.h" | |
17 | 22 |
18 /*------------------------------------------------------------------------* | 23 /*------------------------------------------------------------------------* |
19 * * | 24 * * |
20 * Algorithm: * | 25 * Algorithm: * |
21 * * | 26 * * |
29 /* filter coefficients (fc = 80 Hz, coeff. b[] is divided by 2) */ | 34 /* filter coefficients (fc = 80 Hz, coeff. b[] is divided by 2) */ |
30 | 35 |
31 static const Word16 b[3] = {1899, -3798, 1899}; | 36 static const Word16 b[3] = {1899, -3798, 1899}; |
32 static const Word16 a[3] = {4096, 7807, -3733}; | 37 static const Word16 a[3] = {4096, 7807, -3733}; |
33 | 38 |
34 /* Static values to be preserved between calls */ | |
35 /* y[] values are kept in double precision */ | |
36 | |
37 static Word16 y2_hi, y2_lo, y1_hi, y1_lo, x0, x1; | |
38 | |
39 /* Initialization of static values */ | 39 /* Initialization of static values */ |
40 | 40 |
41 void Init_Pre_Process (void) | 41 void Init_Pre_Process (struct EFR_encoder_state *st) |
42 { | 42 { |
43 y2_hi = 0; | 43 struct preproc_state *pps = &st->pre_proc; |
44 y2_lo = 0; | 44 |
45 y1_hi = 0; | 45 pps->y2_hi = 0; |
46 y1_lo = 0; | 46 pps->y2_lo = 0; |
47 x0 = 0; | 47 pps->y1_hi = 0; |
48 x1 = 0; | 48 pps->y1_lo = 0; |
49 pps->x0 = 0; | |
50 pps->x1 = 0; | |
49 } | 51 } |
50 | 52 |
51 void Pre_Process ( | 53 void Pre_Process ( |
54 struct EFR_encoder_state *st, | |
52 Word16 signal[], /* input/output signal */ | 55 Word16 signal[], /* input/output signal */ |
53 Word16 lg) /* lenght of signal */ | 56 Word16 lg) /* lenght of signal */ |
54 { | 57 { |
58 struct preproc_state *pps = &st->pre_proc; | |
55 Word16 i, x2; | 59 Word16 i, x2; |
56 Word32 L_tmp; | 60 Word32 L_tmp; |
57 | 61 |
58 for (i = 0; i < lg; i++) | 62 for (i = 0; i < lg; i++) |
59 { | 63 { |
60 x2 = x1; move16 (); | 64 x2 = pps->x1; |
61 x1 = x0; move16 (); | 65 pps->x1 = pps->x0; |
62 x0 = signal[i]; move16 (); | 66 pps->x0 = signal[i]; |
63 | 67 |
64 /* y[i] = b[0]*x[i]/2 + b[1]*x[i-1]/2 + b140[2]*x[i-2]/2 */ | 68 /* y[i] = b[0]*x[i]/2 + b[1]*x[i-1]/2 + b140[2]*x[i-2]/2 */ |
65 /* + a[1]*y[i-1] + a[2] * y[i-2]; */ | 69 /* + a[1]*y[i-1] + a[2] * y[i-2]; */ |
66 | 70 |
67 L_tmp = Mpy_32_16 (y1_hi, y1_lo, a[1]); | 71 L_tmp = Mpy_32_16 (pps->y1_hi, pps->y1_lo, a[1]); |
68 L_tmp = L_add (L_tmp, Mpy_32_16 (y2_hi, y2_lo, a[2])); | 72 L_tmp = L_add (L_tmp, Mpy_32_16 (pps->y2_hi, pps->y2_lo, a[2])); |
69 L_tmp = L_mac (L_tmp, x0, b[0]); | 73 L_tmp = L_mac (L_tmp, pps->x0, b[0]); |
70 L_tmp = L_mac (L_tmp, x1, b[1]); | 74 L_tmp = L_mac (L_tmp, pps->x1, b[1]); |
71 L_tmp = L_mac (L_tmp, x2, b[2]); | 75 L_tmp = L_mac (L_tmp, x2, b[2]); |
72 L_tmp = L_shl (L_tmp, 3); | 76 L_tmp = L_shl (L_tmp, 3); |
73 signal[i] = round (L_tmp); move16 (); | 77 signal[i] = round (L_tmp); |
74 | 78 |
75 y2_hi = y1_hi; move16 (); | 79 pps->y2_hi = pps->y1_hi; |
76 y2_lo = y1_lo; move16 (); | 80 pps->y2_lo = pps->y1_lo; |
77 L_Extract (L_tmp, &y1_hi, &y1_lo); | 81 L_Extract (L_tmp, &pps->y1_hi, &pps->y1_lo); |
78 } | 82 } |
79 return; | 83 return; |
80 } | 84 } |