annotate libgsmefr/pre_proc.c @ 274:52c667f17d2c

libgsmfr2: implement gsmfr_0610_encode_frame() wrapper
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Apr 2024 02:57:18 +0000
parents 3ea19a9aa2a1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
53
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*************************************************************************
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * FUNCTION: Pre_Process()
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * PURPOSE: Preprocessing of input speech.
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 * DESCRIPTION:
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 * - 2nd order high pass filtering with cut off frequency at 80 Hz.
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 * - Divide input by two.
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 *************************************************************************/
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
84
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
13 #include "gsm_efr.h"
53
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "typedef.h"
84
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
15 #include "namespace.h"
53
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include "basic_op.h"
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "oper_32b.h"
84
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
18 #include "no_count.h"
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
19 #include "sig_proc.h"
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
20 #include "cnst.h"
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
21 #include "enc_state.h"
53
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 /*------------------------------------------------------------------------*
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 * Algorithm: *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 * y[i] = b[0]*x[i]/2 + b[1]*x[i-1]/2 + b[2]*x[i-2]/2 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 * + a[1]*y[i-1] + a[2]*y[i-2]; *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 * Input is divided by two in the filtering process. *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 *------------------------------------------------------------------------*/
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 /* filter coefficients (fc = 80 Hz, coeff. b[] is divided by 2) */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 static const Word16 b[3] = {1899, -3798, 1899};
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 static const Word16 a[3] = {4096, 7807, -3733};
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 /* Initialization of static values */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40
84
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
41 void Init_Pre_Process (struct EFR_encoder_state *st)
53
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 {
84
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
43 struct preproc_state *pps = &st->pre_proc;
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
44
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
45 pps->y2_hi = 0;
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
46 pps->y2_lo = 0;
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
47 pps->y1_hi = 0;
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
48 pps->y1_lo = 0;
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
49 pps->x0 = 0;
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
50 pps->x1 = 0;
53
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 }
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 void Pre_Process (
84
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
54 struct EFR_encoder_state *st,
53
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 Word16 signal[], /* input/output signal */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 Word16 lg) /* lenght of signal */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 {
84
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
58 struct preproc_state *pps = &st->pre_proc;
53
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 Word16 i, x2;
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 Word32 L_tmp;
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 for (i = 0; i < lg; i++)
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 {
84
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
64 x2 = pps->x1;
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
65 pps->x1 = pps->x0;
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
66 pps->x0 = signal[i];
53
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 /* y[i] = b[0]*x[i]/2 + b[1]*x[i-1]/2 + b140[2]*x[i-2]/2 */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 /* + a[1]*y[i-1] + a[2] * y[i-2]; */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70
84
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
71 L_tmp = Mpy_32_16 (pps->y1_hi, pps->y1_lo, a[1]);
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
72 L_tmp = L_add (L_tmp, Mpy_32_16 (pps->y2_hi, pps->y2_lo, a[2]));
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
73 L_tmp = L_mac (L_tmp, pps->x0, b[0]);
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
74 L_tmp = L_mac (L_tmp, pps->x1, b[1]);
53
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 L_tmp = L_mac (L_tmp, x2, b[2]);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 L_tmp = L_shl (L_tmp, 3);
84
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
77 signal[i] = round (L_tmp);
53
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78
84
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
79 pps->y2_hi = pps->y1_hi;
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
80 pps->y2_lo = pps->y1_lo;
3ea19a9aa2a1 libgsmefr: pre_proc.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
81 L_Extract (L_tmp, &pps->y1_hi, &pps->y1_lo);
53
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 }
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 return;
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 }