annotate libtwamr/agc.h @ 282:9ee8ad3d4d30

frtest: rm gsmfr-hand-test and gsmfr-max-out utils These hack programs were never properly documented and were written only as part of a debug chase, in pursuit of a bug that ultimately turned out to be in our then-hacky patch to osmo-bts-sysmo, before beginning of proper patches in Osmocom. These hack programs need to be dropped from the present sw package because they depend on old libgsm, and we are eliminating that dependency.
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Apr 2024 05:44:47 +0000
parents 54f6bc41ed10
children 6b33f3ba4289
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
253
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 *****************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * R99 Version 3.3.0
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * REL-4 Version 4.1.0
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 *****************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * File : agc.h
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 * Purpose : Scales the postfilter output on a subframe basis
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 * : by automatic control of the subframe gain.
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 *****************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #ifndef agc_h
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #define agc_h "$Id $"
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 /*
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 *****************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 * INCLUDE FILES
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 *****************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 #include "typedef.h"
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 /*
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 *****************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 * DEFINITION OF DATA TYPES
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 *****************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 typedef struct {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 Word16 past_gain;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 } agcState;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 /*
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 *****************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 * DECLARATION OF PROTOTYPES
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 *****************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 /*
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 **************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 * Function : agc_init
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 * Purpose : Allocates memory for agc state and initializes
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 * state memory
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 * Description : Stores pointer to agc status struct in *st. This pointer
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 * has to be passed to agc in each call.
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 * Returns : 0 on success
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 **************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 int agc_init(agcState **st);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 /*
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 **************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 * Function : agc_reset
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 * Purpose : Reset of agc (i.e. set state memory to 1.0)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 * Returns : 0 on success
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 **************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 int agc_reset (agcState *st);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 /*
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 **************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 * Function : agc_exit
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 * Purpose : The memory used for state memory is freed,
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 * de-initialize agc
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 **************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 void agc_exit (agcState **st);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 /*
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 **************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 * Function : agc
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 * Purpose : Scales the postfilter output on a subframe basis
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 * Description : sig_out[n] = sig_out[n] * gain[n];
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 * where gain[n] is the gain at the nth sample given by
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 * gain[n] = agc_fac * gain[n-1] + (1 - agc_fac) g_in/g_out
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 * g_in/g_out is the square root of the ratio of energy at
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 * the input and output of the postfilter.
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 **************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 int agc (
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 agcState *st, /* i/o : agc state */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 Word16 *sig_in, /* i : postfilter input signal, (l_trm) */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 Word16 *sig_out, /* i/o : postfilter output signal, (l_trm) */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 Word16 agc_fac, /* i : AGC factor */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 Word16 l_trm /* i : subframe size */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 );
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 /*
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 **************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 * Function: agc2
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 * Purpose: Scales the excitation on a subframe basis
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 **************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 void agc2 (
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 Word16 *sig_in, /* i : postfilter input signal */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 Word16 *sig_out, /* i/o : postfilter output signal */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 Word16 l_trm /* i : subframe size */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 );
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 #endif