FreeCalypso > hg > gsm-codec-lib
annotate libtwamr/g_adapt.c @ 426:7bef001cd8b8
libtwamr: integrate dec_amr.c
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 07 May 2024 20:33:01 +0000 |
parents | 2a265be82195 |
children |
rev | line source |
---|---|
365
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 ******************************************************************************** |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * R99 Version 3.3.0 |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * REL-4 Version 4.1.0 |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 ******************************************************************************** |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 * |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 * File : g_adapt.c |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 * Purpose : gain adaptation for MR795 gain quantization |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 * |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 ******************************************************************************** |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 /* |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 ******************************************************************************** |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 * MODULE INCLUDE FILE AND VERSION ID |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 ******************************************************************************** |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 #include "namespace.h" |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 #include "g_adapt.h" |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 /* |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 ******************************************************************************** |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 * INCLUDE FILES |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 ******************************************************************************** |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 #include "typedef.h" |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 #include "basic_op.h" |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 #include "oper_32b.h" |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 #include "no_count.h" |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 #include "cnst.h" |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 #include "gmed_n.h" |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 /* |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 ******************************************************************************** |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 * LOCAL VARIABLES AND TABLES |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 ******************************************************************************** |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 #define LTP_GAIN_THR1 2721 /* 2721 Q13 = 0.3322 ~= 1.0 / (10*log10(2)) */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 #define LTP_GAIN_THR2 5443 /* 5443 Q13 = 0.6644 ~= 2.0 / (10*log10(2)) */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 /* |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 ******************************************************************************** |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 * PUBLIC PROGRAM CODE |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 ******************************************************************************** |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 /************************************************************************* |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 * |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 * Function: gain_adapt_reset |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 * Purpose: Initializes state memory to zero |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 * |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 ************************************************************************** |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 void gain_adapt_reset (GainAdaptState *st) |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 { |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 Word16 i; |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 st->onset = 0; |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 st->prev_alpha = 0; |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 st->prev_gc = 0; |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 for (i = 0; i < LTPG_MEM_SIZE; i++) |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 { |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 st->ltpg_mem[i] = 0; |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 } |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 } |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 /************************************************************************* |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 * |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 * Function: gain_adapt() |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 * Purpose: calculate pitch/codebook gain adaptation factor alpha |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 * (and update the adaptor state) |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 * |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 ************************************************************************** |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 void gain_adapt( |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 GainAdaptState *st, /* i : state struct */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 Word16 ltpg, /* i : ltp coding gain (log2()), Q13 */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 Word16 gain_cod, /* i : code gain, Q1 */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 Word16 *alpha /* o : gain adaptation factor, Q15 */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 ) |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 { |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 Word16 adapt; /* adaptdation status; 0, 1, or 2 */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 Word16 result; /* alpha factor, Q13 */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 Word16 filt; /* median-filtered LTP coding gain, Q13 */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 Word16 tmp, i; |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 /* basic adaptation */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 test (); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 if (sub (ltpg, LTP_GAIN_THR1) <= 0) |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 { |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 adapt = 0; move16 (); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 } |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 else |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 { |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 test (); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 if (sub (ltpg, LTP_GAIN_THR2) <= 0) |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 { |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 adapt = 1; move16 (); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 } |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 else |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 { |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 adapt = 2; move16 (); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 } |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 } |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 /* |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 * // onset indicator |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 * if ((cbGain > onFact * cbGainMem[0]) && (cbGain > 100.0)) |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 * onset = 8; |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 * else |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 * if (onset) |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 * onset--; |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 /* tmp = cbGain / onFact; onFact = 2.0; 200 Q1 = 100.0 */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 tmp = shr_r (gain_cod, 1); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 test (); test (); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 if ((sub (tmp, st->prev_gc) > 0) && sub(gain_cod, 200) > 0) |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 { |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 st->onset = 8; move16 (); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 } |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 else |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 { |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 test (); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 if (st->onset != 0) |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 { |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 st->onset = sub (st->onset, 1); move16 (); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 } |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 } |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 /* |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 * // if onset, increase adaptor state |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 * if (onset && (gainAdapt < 2)) gainAdapt++; |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 test(); test (); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 if ((st->onset != 0) && (sub (adapt, 2) < 0)) |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 { |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 adapt = add (adapt, 1); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 } |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 st->ltpg_mem[0] = ltpg; move16 (); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 filt = gmed_n (st->ltpg_mem, 5); move16 (); /* function result */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 test (); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 if (adapt == 0) |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 { |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 test (); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 if (sub (filt, 5443) > 0) /* 5443 Q13 = 0.66443... */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 { |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 result = 0; move16 (); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 } |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 else |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 { |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 test (); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 if (filt < 0) |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 { |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 result = 16384; move16 (); /* 16384 Q15 = 0.5 */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 } |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 else |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 { /* result = 0.5 - 0.75257499*filt */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 /* result (Q15) = 16384 - 24660 * (filt << 2) */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 filt = shl (filt, 2); /* Q15 */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 result = sub (16384, mult (24660, filt)); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 } |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 } |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 } |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 else |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 { |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 result = 0; move16 (); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 } |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 /* |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 * if (prevAlpha == 0.0) result = 0.5 * (result + prevAlpha); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 test (); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 if (st->prev_alpha == 0) |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 { |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 result = shr (result, 1); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 } |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 /* store the result */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 *alpha = result; move16 (); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 /* update adapter state memory */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 st->prev_alpha = result; move16 (); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 st->prev_gc = gain_cod; move16 (); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 for (i = LTPG_MEM_SIZE-1; i > 0; i--) |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 { |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 st->ltpg_mem[i] = st->ltpg_mem[i-1]; move16 (); |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 } |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 /* mem[0] is just present for convenience in calling the gmed_n[5] |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 * function above. The memory depth is really LTPG_MEM_SIZE-1. |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 */ |
2a265be82195
libtwamr: integrate g_adapt.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 } |