1
0
mirror of git://projects.qi-hardware.com/antorcha.git synced 2024-11-25 18:14:05 +02:00

tornado/fw/sim/alg.c: separate data processing from sample generation

This commit is contained in:
Werner Almesberger 2012-12-09 16:29:00 -03:00
parent 4d09658036
commit 07e0df0d6a

View File

@ -44,16 +44,14 @@ static uint16_t sample(double t)
#define E_SHIFT 3 /* ~ 0.1 */ #define E_SHIFT 3 /* ~ 0.1 */
#define M_SHIFT 10 /* ~ 1/S */ #define M_SHIFT 10 /* ~ 1/S */
int main(void)
static void process(unsigned v)
{ {
uint16_t e = MID << E_SHIFT; uint16_t e = MID << E_SHIFT;
uint32_t m = MID << M_SHIFT; uint32_t m = MID << M_SHIFT;
int d; int d;
int i;
bool up = 0; bool up = 0;
for (i = 0; i != 10*S; i++) {
unsigned v = sample((double) i/S);
e = v+(e-(e >> E_SHIFT)); e = v+(e-(e >> E_SHIFT));
m = v+(m-(m >> M_SHIFT)); m = v+(m-(m >> M_SHIFT));
d = (e >> E_SHIFT)-(m >> M_SHIFT); d = (e >> E_SHIFT)-(m >> M_SHIFT);
@ -66,6 +64,17 @@ int main(void)
} }
printf("%d %d %d %d %d\n", printf("%d %d %d %d %d\n",
v, e >> E_SHIFT, m >> M_SHIFT, d, up); v, e >> E_SHIFT, m >> M_SHIFT, d, up);
}
int main(void)
{
int i;
for (i = 0; i != 10*S; i++) {
unsigned v = sample((double) i/S);
process(v);
} }
return 0; return 0;
} }