comparison libtwamr/agc.c @ 307:6b33f3ba4289

libtwamr: go for single-chunk-state approach
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 16 Apr 2024 17:18:04 +0000
parents 07f936338de1
children
comparison
equal deleted inserted replaced
306:047c198408c8 307:6b33f3ba4289
23 /* 23 /*
24 ***************************************************************************** 24 *****************************************************************************
25 * INCLUDE FILES 25 * INCLUDE FILES
26 ***************************************************************************** 26 *****************************************************************************
27 */ 27 */
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include "typedef.h" 28 #include "typedef.h"
31 #include "basic_op.h" 29 #include "basic_op.h"
32 #include "no_count.h" 30 #include "no_count.h"
33 #include "cnst.h" 31 #include "cnst.h"
34 #include "inv_sqrt.h" 32 #include "inv_sqrt.h"
102 ***************************************************************************** 100 *****************************************************************************
103 */ 101 */
104 /* 102 /*
105 ************************************************************************** 103 **************************************************************************
106 * 104 *
107 * Function : agc_init
108 * Purpose : Allocates memory for agc state and initializes
109 * state memory
110 *
111 **************************************************************************
112 */
113 int agc_init (agcState **state)
114 {
115 agcState* s;
116
117 if (state == (agcState **) NULL){
118 fprintf(stderr, "agc_init: invalid parameter\n");
119 return -1;
120 }
121 *state = NULL;
122
123 /* allocate memory */
124 if ((s= (agcState *) malloc(sizeof(agcState))) == NULL){
125 fprintf(stderr, "agc_init: can not malloc state structure\n");
126 return -1;
127 }
128
129 agc_reset(s);
130 *state = s;
131
132 return 0;
133 }
134
135 /*
136 **************************************************************************
137 *
138 * Function : agc_reset 105 * Function : agc_reset
139 * Purpose : Reset of agc (i.e. set state memory to 1.0) 106 * Purpose : Reset of agc (i.e. set state memory to 1.0)
140 * 107 *
141 ************************************************************************** 108 **************************************************************************
142 */ 109 */
143 int agc_reset (agcState *state) 110 void agc_reset (agcState *state)
144 { 111 {
145 if (state == (agcState *) NULL){
146 fprintf(stderr, "agc_reset: invalid parameter\n");
147 return -1;
148 }
149
150 state->past_gain = 4096; /* initial value of past_gain = 1.0 */ 112 state->past_gain = 4096; /* initial value of past_gain = 1.0 */
151
152 return 0;
153 }
154
155 /*
156 **************************************************************************
157 *
158 * Function : agc_exit
159 * Purpose : The memory used for state memory is freed
160 *
161 **************************************************************************
162 */
163 void agc_exit (agcState **state)
164 {
165 if (state == NULL || *state == NULL)
166 return;
167
168 /* deallocate memory */
169 free(*state);
170 *state = NULL;
171
172 return;
173 } 113 }
174 114
175 /* 115 /*
176 ************************************************************************** 116 **************************************************************************
177 * 117 *