annotate libtwamr/agc.c @ 253:54f6bc41ed10

libtwamr: integrate a* modules
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 05 Apr 2024 06:08:15 +0000
parents
children 07f936338de1
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 const char agc_id[] = "@(#)$Id $" agc_h;
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 *****************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 * INCLUDE FILES
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 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 #include <stdlib.h>
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 #include <stdio.h>
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 #include "typedef.h"
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 #include "basic_op.h"
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 #include "no_count.h"
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 #include "cnst.h"
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 #include "inv_sqrt.h"
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 *****************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 * LOCAL VARIABLES AND TABLES
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 *****************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 * LOCAL PROGRAM CODE
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
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 static Word32 energy_old( /* o : return energy of signal */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 Word16 in[], /* i : input signal (length l_trm) */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 Word16 l_trm /* i : signal length */
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 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 Word32 s;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 Word16 i, temp;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 temp = shr (in[0], 2);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 s = L_mult (temp, temp);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 for (i = 1; i < l_trm; i++)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 temp = shr (in[i], 2);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 s = L_mac (s, temp, temp);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 return s;
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
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 static Word32 energy_new( /* o : return energy of signal */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 Word16 in[], /* i : input signal (length l_trm) */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 Word16 l_trm /* i : signal length */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 )
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 Word32 s;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 Word16 i;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 Flag ov_save;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 ov_save = Overflow; move16 (); /* save overflow flag in case energy_old */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 /* must be called */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 s = L_mult(in[0], in[0]);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 for (i = 1; i < l_trm; i++)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 s = L_mac(s, in[i], in[i]);
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
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 /* check for overflow */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 test ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 if (L_sub (s, MAX_32) == 0L)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 Overflow = ov_save; move16 (); /* restore overflow flag */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 s = energy_old (in, l_trm); move32 (); /* function result */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 else
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 s = L_shr(s, 4);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 return s;
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 *****************************************************************************
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 * PUBLIC PROGRAM CODE
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 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 * Function : agc_init
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 * Purpose : Allocates memory for agc state and initializes
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 * state memory
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 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 int agc_init (agcState **state)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 agcState* s;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 if (state == (agcState **) NULL){
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 fprintf(stderr, "agc_init: invalid parameter\n");
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 return -1;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 *state = NULL;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 /* allocate memory */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 if ((s= (agcState *) malloc(sizeof(agcState))) == NULL){
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 fprintf(stderr, "agc_init: can not malloc state structure\n");
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 return -1;
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
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 agc_reset(s);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 *state = s;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 return 0;
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 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 * Function : agc_reset
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 * 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
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 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 int agc_reset (agcState *state)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 if (state == (agcState *) NULL){
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 fprintf(stderr, "agc_reset: invalid parameter\n");
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 return -1;
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
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 state->past_gain = 4096; /* initial value of past_gain = 1.0 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 return 0;
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 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 * Function : agc_exit
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 * Purpose : The memory used for state memory is freed
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 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 void agc_exit (agcState **state)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 if (state == NULL || *state == NULL)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 return;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 /* deallocate memory */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 free(*state);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 *state = NULL;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 return;
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 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 * Function : agc
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 * Purpose : Scales the postfilter output on a subframe basis
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 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 int agc (
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 agcState *st, /* i/o : agc state */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 Word16 *sig_in, /* i : postfilter input signal (l_trm) */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 Word16 *sig_out, /* i/o : postfilter output signal (l_trm) */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 Word16 agc_fac, /* i : AGC factor */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 Word16 l_trm /* i : subframe size */
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 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 Word16 i, exp;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 Word16 gain_in, gain_out, g0, gain;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 Word32 s;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 /* calculate gain_out with exponent */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 s = energy_new(sig_out, l_trm); move32 (); /* function result */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 test ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 if (s == 0)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 st->past_gain = 0; move16 ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 return 0;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 exp = sub (norm_l (s), 1);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 gain_out = round (L_shl (s, exp));
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 /* calculate gain_in with exponent */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 s = energy_new(sig_in, l_trm); move32 (); /* function result */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 test ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 if (s == 0)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 g0 = 0; move16 ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 else
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 i = norm_l (s);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 gain_in = round (L_shl (s, i));
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 exp = sub (exp, i);
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 /*---------------------------------------------------*
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 * g0 = (1-agc_fac) * sqrt(gain_in/gain_out); *
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
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 s = L_deposit_l (div_s (gain_out, gain_in));
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 s = L_shl (s, 7); /* s = gain_out / gain_in */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 s = L_shr (s, exp); /* add exponent */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 s = Inv_sqrt (s); move32 (); /* function result */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 i = round (L_shl (s, 9));
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 /* g0 = i * (1-agc_fac) */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 g0 = mult (i, sub (32767, agc_fac));
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
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 /* compute gain[n] = agc_fac * gain[n-1]
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 + (1-agc_fac) * sqrt(gain_in/gain_out) */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 /* sig_out[n] = gain[n] * sig_out[n] */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 gain = st->past_gain; move16 ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 for (i = 0; i < l_trm; i++)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 gain = mult (gain, agc_fac);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 gain = add (gain, g0);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 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
248 move16 ();
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
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251 st->past_gain = gain; move16 ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 return 0;
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 *
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259 * Function : agc2
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 * Purpose : Scales the excitation on a subframe basis
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 */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 void agc2 (
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265 Word16 *sig_in, /* i : postfilter input signal */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 Word16 *sig_out, /* i/o : postfilter output signal */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 Word16 l_trm /* i : subframe size */
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 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270 Word16 i, exp;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
271 Word16 gain_in, gain_out, g0;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272 Word32 s;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274 /* calculate gain_out with exponent */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
275 s = energy_new(sig_out, l_trm); move32 (); /* function result */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
277 test ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
278 if (s == 0)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
279 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
280 return;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
281 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
282 exp = sub (norm_l (s), 1);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
283 gain_out = round (L_shl (s, exp));
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
284
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
285 /* calculate gain_in with exponent */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
286 s = energy_new(sig_in, l_trm); move32 (); /* function result */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
287
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
288 test ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
289 if (s == 0)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
290 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
291 g0 = 0; move16 ();
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
292 }
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
293 else
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
294 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
295 i = norm_l (s);
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
296 gain_in = round (L_shl (s, i));
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
297 exp = sub (exp, i);
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 /*---------------------------------------------------*
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
300 * g0 = sqrt(gain_in/gain_out); *
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
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
303 s = L_deposit_l (div_s (gain_out, gain_in));
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
304 s = L_shl (s, 7); /* s = gain_out / gain_in */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
305 s = L_shr (s, exp); /* add exponent */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
306
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
307 s = Inv_sqrt (s); move32 (); /* function result */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
308 g0 = round (L_shl (s, 9));
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
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
311 /* sig_out(n) = gain(n) sig_out(n) */
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
312
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
313 for (i = 0; i < l_trm; i++)
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
314 {
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
315 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
316 move16 ();
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
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
319 return;
54f6bc41ed10 libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
320 }