annotate src/agc_amr.c @ 8:8b17df8f6340 default tip

add README
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 17 Apr 2024 17:30:25 +0000
parents c511bfb36c2a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 *****************************************************************************
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 *
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * R99 Version 3.3.0
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * REL-4 Version 4.1.0
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 *
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 *****************************************************************************
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 *
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * File : agc.c
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 *
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 *****************************************************************************
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 /*
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 *****************************************************************************
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 * MODULE INCLUDE FILE AND VERSION ID
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 *****************************************************************************
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 #if 0
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #include "agc.h"
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 const char agc_id[] = "@(#)$Id $" agc_h;
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 #endif
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 /*
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 *****************************************************************************
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 * INCLUDE FILES
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 *****************************************************************************
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 #include <stdlib.h>
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 #include <stdio.h>
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 #include "typedef.h"
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 #include "basic_op.h"
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 #include "count.h"
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 #include "sig_proc.h"
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 #include "cnst.h"
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 Word16 past_gain; /* initial value of past_gain = 1.0 */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 /*
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 *****************************************************************************
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 * LOCAL PROGRAM CODE
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 *****************************************************************************
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 static Word32 energy_old( /* o : return energy of signal */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 Word16 in[], /* i : input signal (length l_trm) */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 Word16 l_trm /* i : signal length */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 )
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 {
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 Word32 s;
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 Word16 i, temp;
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 temp = shr (in[0], 2);
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 s = L_mult (temp, temp);
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 for (i = 1; i < l_trm; i++)
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 {
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 temp = shr (in[i], 2);
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 s = L_mac (s, temp, temp);
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 return s;
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 static Word32 energy_new( /* o : return energy of signal */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 Word16 in[], /* i : input signal (length l_trm) */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 Word16 l_trm /* i : signal length */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 )
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 {
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 Word32 s;
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 Word16 i;
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 Flag ov_save;
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 ov_save = Overflow; move16 (); /* save overflow flag in case energy_old */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 /* must be called */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 s = L_mult(in[0], in[0]);
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 for (i = 1; i < l_trm; i++)
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 {
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 s = L_mac(s, in[i], in[i]);
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 }
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 /* check for overflow */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 test ();
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 if (L_sub (s, MAX_32) == 0L)
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 {
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 Overflow = ov_save; move16 (); /* restore overflow flag */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 s = energy_old (in, l_trm); move32 (); /* function result */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 }
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 else
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 {
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 s = L_shr(s, 4);
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 }
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 return s;
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 }
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 /*
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 *****************************************************************************
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 * PUBLIC PROGRAM CODE
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 *****************************************************************************
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 /*
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 **************************************************************************
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 *
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 * Function : agc
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 * Purpose : Scales the postfilter output on a subframe basis
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 *
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 **************************************************************************
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 void agc (
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 Word16 *sig_in, /* i : postfilter input signal (l_trm) */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 Word16 *sig_out, /* i/o : postfilter output signal (l_trm) */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 Word16 agc_fac, /* i : AGC factor */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 Word16 l_trm /* i : subframe size */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 )
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 {
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 Word16 i, exp;
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 Word16 gain_in, gain_out, g0, gain;
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 Word32 s;
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 /* calculate gain_out with exponent */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 s = energy_new(sig_out, l_trm); move32 (); /* function result */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 test ();
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 if (s == 0)
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 {
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 past_gain = 0; move16 ();
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 return;
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 }
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 exp = sub (norm_l (s), 1);
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 gain_out = round (L_shl (s, exp));
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 /* calculate gain_in with exponent */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 s = energy_new(sig_in, l_trm); move32 (); /* function result */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 test ();
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 if (s == 0)
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 {
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 g0 = 0; move16 ();
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 }
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 else
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 {
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 i = norm_l (s);
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 gain_in = round (L_shl (s, i));
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 exp = sub (exp, i);
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 /*---------------------------------------------------*
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 * g0 = (1-agc_fac) * sqrt(gain_in/gain_out); *
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 *---------------------------------------------------*/
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 s = L_deposit_l (div_s (gain_out, gain_in));
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 s = L_shl (s, 7); /* s = gain_out / gain_in */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 s = L_shr (s, exp); /* add exponent */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 s = Inv_sqrt (s); move32 (); /* function result */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 i = round (L_shl (s, 9));
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 /* g0 = i * (1-agc_fac) */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 g0 = mult (i, sub (32767, agc_fac));
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 }
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 /* compute gain[n] = agc_fac * gain[n-1]
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 + (1-agc_fac) * sqrt(gain_in/gain_out) */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 /* sig_out[n] = gain[n] * sig_out[n] */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 gain = past_gain; move16 ();
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 for (i = 0; i < l_trm; i++)
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 {
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 gain = mult (gain, agc_fac);
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 gain = add (gain, g0);
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 sig_out[i] = extract_h (L_shl (L_mult (sig_out[i], gain), 3));
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 move16 ();
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 }
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 past_gain = gain; move16 ();
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 }
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 /*
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 **************************************************************************
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 *
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 * Function : agc2
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 * Purpose : Scales the excitation on a subframe basis
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 *
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 **************************************************************************
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 void agc2 (
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 Word16 *sig_in, /* i : postfilter input signal */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 Word16 *sig_out, /* i/o : postfilter output signal */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 Word16 l_trm /* i : subframe size */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 )
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 {
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 Word16 i, exp;
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 Word16 gain_in, gain_out, g0;
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 Word32 s;
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 /* calculate gain_out with exponent */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 s = energy_new(sig_out, l_trm); move32 (); /* function result */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 test ();
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 if (s == 0)
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 {
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 return;
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 }
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 exp = sub (norm_l (s), 1);
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 gain_out = round (L_shl (s, exp));
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 /* calculate gain_in with exponent */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 s = energy_new(sig_in, l_trm); move32 (); /* function result */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 test ();
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 if (s == 0)
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 {
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 g0 = 0; move16 ();
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 }
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 else
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 {
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 i = norm_l (s);
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 gain_in = round (L_shl (s, i));
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 exp = sub (exp, i);
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 /*---------------------------------------------------*
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 * g0 = sqrt(gain_in/gain_out); *
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 *---------------------------------------------------*/
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 s = L_deposit_l (div_s (gain_out, gain_in));
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 s = L_shl (s, 7); /* s = gain_out / gain_in */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 s = L_shr (s, exp); /* add exponent */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 s = Inv_sqrt (s); move32 (); /* function result */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 g0 = round (L_shl (s, 9));
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 }
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 /* sig_out(n) = gain(n) sig_out(n) */
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 for (i = 0; i < l_trm; i++)
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 {
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 sig_out[i] = extract_h (L_shl (L_mult (sig_out[i], g0), 3));
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 move16 ();
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 }
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 return;
c511bfb36c2a beginning of EFR2 decoder, using AMR version of AGC module
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 }