annotate libtwamr/agc.c @ 287:f00925b533b7

gsmfr-encode: convert to libgsmfr2
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Apr 2024 06:16:47 +0000
parents 07f936338de1
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.c
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 *****************************************************************************
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 *****************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 * MODULE INCLUDE FILE AND VERSION 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 #include "namespace.h"
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #include "agc.h"
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 *****************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 * INCLUDE FILES
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 #include <stdlib.h>
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 #include <stdio.h>
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 #include "typedef.h"
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 #include "basic_op.h"
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 #include "no_count.h"
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 #include "cnst.h"
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 #include "inv_sqrt.h"
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 *****************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 * LOCAL VARIABLES AND TABLES
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 *****************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 * LOCAL PROGRAM CODE
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 *****************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 static Word32 energy_old( /* o : return energy of signal */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 Word16 in[], /* i : input signal (length l_trm) */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 Word16 l_trm /* i : signal length */
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 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 Word32 s;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 Word16 i, temp;
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 temp = shr (in[0], 2);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 s = L_mult (temp, temp);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 for (i = 1; i < l_trm; i++)
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 temp = shr (in[i], 2);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 s = L_mac (s, temp, temp);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
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 return s;
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 static Word32 energy_new( /* o : return energy of signal */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 Word16 in[], /* i : input signal (length l_trm) */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 Word16 l_trm /* i : signal length */
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 Word32 s;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 Word16 i;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 Flag ov_save;
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 ov_save = Overflow; move16 (); /* save overflow flag in case energy_old */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 /* must be called */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 s = L_mult(in[0], in[0]);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 for (i = 1; i < l_trm; i++)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 s = L_mac(s, in[i], in[i]);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 /* check for overflow */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 test ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 if (L_sub (s, MAX_32) == 0L)
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 Overflow = ov_save; move16 (); /* restore overflow flag */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 s = energy_old (in, l_trm); move32 (); /* function result */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 else
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 s = L_shr(s, 4);
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 return s;
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 *****************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 * PUBLIC PROGRAM CODE
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 **************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 * Function : agc_init
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 * Purpose : Allocates memory for agc state and initializes
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 * state memory
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 **************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 int agc_init (agcState **state)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 agcState* s;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 if (state == (agcState **) NULL){
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 fprintf(stderr, "agc_init: invalid parameter\n");
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 return -1;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 *state = NULL;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 /* allocate memory */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 if ((s= (agcState *) malloc(sizeof(agcState))) == NULL){
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 fprintf(stderr, "agc_init: can not malloc state structure\n");
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 return -1;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 agc_reset(s);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 *state = s;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 return 0;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 /*
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 **************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 * Function : agc_reset
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 * 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
140 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 **************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 int agc_reset (agcState *state)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 if (state == (agcState *) NULL){
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 fprintf(stderr, "agc_reset: invalid parameter\n");
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 return -1;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 state->past_gain = 4096; /* initial value of past_gain = 1.0 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 return 0;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 /*
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 **************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 * Function : agc_exit
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 * Purpose : The memory used for state memory is freed
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 **************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 void agc_exit (agcState **state)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 if (state == NULL || *state == NULL)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 return;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 /* deallocate memory */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 free(*state);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 *state = NULL;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 return;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 /*
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 **************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 * Function : agc
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 * Purpose : Scales the postfilter output on a subframe basis
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 **************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 int agc (
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 agcState *st, /* i/o : agc state */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 Word16 *sig_in, /* i : postfilter input signal (l_trm) */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 Word16 *sig_out, /* i/o : postfilter output signal (l_trm) */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 Word16 agc_fac, /* i : AGC factor */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 Word16 l_trm /* i : subframe size */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 )
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 Word16 i, exp;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 Word16 gain_in, gain_out, g0, gain;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 Word32 s;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 /* calculate gain_out with exponent */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 s = energy_new(sig_out, l_trm); move32 (); /* function result */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 test ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 if (s == 0)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 st->past_gain = 0; move16 ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 return 0;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 exp = sub (norm_l (s), 1);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 gain_out = round (L_shl (s, exp));
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 /* calculate gain_in with exponent */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 s = energy_new(sig_in, l_trm); move32 (); /* function result */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 test ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 if (s == 0)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 g0 = 0; move16 ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 else
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 i = norm_l (s);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 gain_in = round (L_shl (s, i));
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 exp = sub (exp, i);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 /*---------------------------------------------------*
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 * g0 = (1-agc_fac) * sqrt(gain_in/gain_out); *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 *---------------------------------------------------*/
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 s = L_deposit_l (div_s (gain_out, gain_in));
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 s = L_shl (s, 7); /* s = gain_out / gain_in */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 s = L_shr (s, exp); /* add exponent */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 s = Inv_sqrt (s); move32 (); /* function result */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 i = round (L_shl (s, 9));
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 /* g0 = i * (1-agc_fac) */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 g0 = mult (i, sub (32767, agc_fac));
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 /* compute gain[n] = agc_fac * gain[n-1]
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 + (1-agc_fac) * sqrt(gain_in/gain_out) */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 /* sig_out[n] = gain[n] * sig_out[n] */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 gain = st->past_gain; move16 ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 for (i = 0; i < l_trm; i++)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 gain = mult (gain, agc_fac);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 gain = add (gain, g0);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 sig_out[i] = extract_h (L_shl (L_mult (sig_out[i], gain), 3));
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 move16 ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 st->past_gain = gain; move16 ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252 return 0;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 /*
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256 **************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 * Function : agc2
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259 * Purpose : Scales the excitation on a subframe basis
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261 **************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263 void agc2 (
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 Word16 *sig_in, /* i : postfilter input signal */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265 Word16 *sig_out, /* i/o : postfilter output signal */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 Word16 l_trm /* i : subframe size */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 )
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269 Word16 i, exp;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270 Word16 gain_in, gain_out, g0;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
271 Word32 s;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 /* calculate gain_out with exponent */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274 s = energy_new(sig_out, l_trm); move32 (); /* function result */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
275
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276 test ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
277 if (s == 0)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
278 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
279 return;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
280 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
281 exp = sub (norm_l (s), 1);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
282 gain_out = round (L_shl (s, exp));
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
283
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
284 /* calculate gain_in with exponent */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
285 s = energy_new(sig_in, l_trm); move32 (); /* function result */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
286
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
287 test ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
288 if (s == 0)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
289 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
290 g0 = 0; move16 ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
291 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
292 else
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
293 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
294 i = norm_l (s);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
295 gain_in = round (L_shl (s, i));
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
296 exp = sub (exp, i);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
297
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
298 /*---------------------------------------------------*
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
299 * g0 = sqrt(gain_in/gain_out); *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
300 *---------------------------------------------------*/
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
301
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
302 s = L_deposit_l (div_s (gain_out, gain_in));
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
303 s = L_shl (s, 7); /* s = gain_out / gain_in */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
304 s = L_shr (s, exp); /* add exponent */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
305
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
306 s = Inv_sqrt (s); move32 (); /* function result */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
307 g0 = round (L_shl (s, 9));
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
308 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
309
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
310 /* sig_out(n) = gain(n) sig_out(n) */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
311
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
312 for (i = 0; i < l_trm; i++)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
313 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
314 sig_out[i] = extract_h (L_shl (L_mult (sig_out[i], g0), 3));
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
315 move16 ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
316 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
317
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
318 return;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
319 }