add oversampler

This commit is contained in:
2024-05-24 13:28:31 +02:00
parent e4a4a661a0
commit 989dba5a6b
484 changed files with 313937 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
gfx_init("vis",1024,768);
zp=-0.84;
fill=0;
radj=1;
while ((c=gfx_getchar())!=27 && c >= 0)
(
c == 'f' ? fill=!fill;
c == 'j' ? jitter=!jitter;
c == 'm' ? radj = !radj;
gfx_r=gfx_g=gfx_b=1;
gfx_a=1;
gfx_x=gfx_y=0;
gfx_printf("[f]ill=%s, [j]itter=%s, [m]ove=%s [%f] %d,%d",fill?"on":"off",jitter?"on":"off",radj?"on":"off",zp,mouse_x,mouse_y);
gfx_a=0.25;
radj ? zp+=0.03;
gfx_getchar('up') ? zp+=0.03;
gfx_getchar('down') ? zp-=0.03;
zp2+=0.1;
rd = (1+sin(zp*1.3))*(gfx_w/8-16) + 3;
jitter ? (
xoffs=0.5+sin(zp2*6.7)*0.5;
yoffs=0.5+sin(zp2*7.7)*0.5;
rd|=0;
rd += 0.5+sin(zp2*3.1)*0.5
) : ( xoffs=yoffs=0; rd|= 0;);
gfx_circle(xoffs+(gfx_w/4)|0,yoffs+(gfx_h/2)|0,rd, fill,0);
gfx_circle(xoffs+(gfx_w*3/4)|0,yoffs+(gfx_h/2)|0,rd, fill,1);
gfx_mode=4+(1<<4); // filtering off, additive
gfx_a=1;
zsz=20;
outsz=gfx_w/4;
gfx_blit(-1,0,0,
gfx_w/4-zsz, gfx_h/2-zsz, zsz*2,zsz*2,
0,gfx_h-outsz,outsz,outsz);
gfx_blit(-1,0,0,
gfx_w*3/4-zsz, gfx_h/2-zsz, zsz*2,zsz*2,
gfx_w-outsz,gfx_h-outsz,outsz,outsz);
gfx_mode=0;
gfx_update();
sleep(30);
);

View File

@@ -0,0 +1,20 @@
argc < 2 ? (
printf("Usage: %s [script]\n",argv[0]);
) : (
printf("loading '%s'\n",argv[1]);
x = fopen(argv[1],"r");
!x ? (
printf("Error opening '%s'\n",argv[1])
) : (
#str="";
while (fgets(x,#line)) ( #str += #line; );
fclose(x);
loop(30,
start_t = time_precise();
eval(#str) || printf("error evaluating script\n");
start_t = time_precise()-start_t;
printf("finished in %f milliseconds\n",start_t*1000.0);
);
);
);

View File

@@ -0,0 +1,24 @@
gfx_init("vis",1024,768);
gfx_clear=-1;
while ((c=gfx_getchar())!=27 && c >= 0)
(
c == ' ' ? (mode += 1) >= 2 ? mode=0;
t=time_precise();
zsc = 0.01*cos(t*0.73);
// gfx_x=gfx_y=0; gfx_blurto(gfx_w,gfx_h);
gfx_blit(-1,0,0.3*(sin(t*0.3)^2),gfx_w*zsc,gfx_h*zsc, gfx_w*(1-2*zsc),gfx_h*(1-2*zsc), 0,0,gfx_w,gfx_h);
gfx_r=(cos(t)+1.0)*0.5;
gfx_g=(cos(t*1.74)+1.0)*0.5;
gfx_b=(cos(t*1.2+0.56)+1.0)*0.5;
gfx_a=0.15;
sz=gfx_w*0.03;
loop(20,
mode == 1 ?
gfx_circle(rand(gfx_w-sz),rand(gfx_h-sz),sz,1) :
gfx_rect(rand(gfx_w-sz),rand(gfx_h-sz),sz,sz);
);
gfx_update();
);

View File

@@ -0,0 +1,29 @@
gfx_init("vis",1024,768);
gfx_clear=-1;
function frame()
(
c=gfx_getchar();
c == ' ' ? (mode += 1) >= 2 ? mode=0;
t=time_precise();
zsc = 0.01*cos(t*0.73);
// gfx_x=gfx_y=0; gfx_blurto(gfx_w,gfx_h);
gfx_blit(-1,0,0.3*(sin(t*0.3)^2),gfx_w*zsc,gfx_h*zsc, gfx_w*(1-2*zsc),gfx_h*(1-2*zsc), 0,0,gfx_w,gfx_h);
gfx_r=(cos(t)+1.0)*0.5;
gfx_g=(cos(t*1.74)+1.0)*0.5;
gfx_b=(cos(t*1.2+0.56)+1.0)*0.5;
gfx_a=0.15;
sz=gfx_w*0.03;
loop(20,
mode == 1 ?
gfx_circle(rand(gfx_w-sz),rand(gfx_h-sz),sz,1) :
gfx_rect(rand(gfx_w-sz),rand(gfx_h-sz),sz,sz);
);
gfx_update();
c>=0 && c != 27 ? defer("frame()");
);
frame();

View File

@@ -0,0 +1,208 @@
// does not work for all .gpx files
// writes to output on every mouseup after edit
// move points with mouse, alt+click to delete
// click/drag to pan
// mousewheel to zoom
tab = 10000;
tabsz = 0;
is_dirty = 0;
circle_size = 5;
function scale(v) global() ( (v - this.min) / (this.max-this.min) );
function unscale(v) global() ( v * (this.max-this.min) + this.min);
function zoom(sc) global() local(c h) (
h = (this.max - this.min) * sc;
c = (this.max + this.min) * .5;
this.max = c + h*.5;
this.min = c - h*.5;
);
function include(v) global() ( this.min = min(v,this.min); this.max = max(v,this.max); );
function scroll(amt) global() ( amt *= (this.max-this.min); this.max += amt; this.min += amt; );
function zoom_view(sc) ( v_lon.zoom(sc); v_lat.zoom(sc); );
function scroll_view(dx, dy) ( v_lat.scroll(-dy/gfx_h); v_lon.scroll(-dx/gfx_w); );
function hit_test(x,y,p) global(tab tabsz circle_size gfx_w gfx_h v_lat.scale v_lon.scale) local(p hit) (
hit = -1;
while (p < tabsz && hit < 0) (
sqr(v_lat.scale(tab[p*2+1])*gfx_h-y)+sqr(v_lon.scale(tab[p*2])*gfx_w-x) < circle_size*circle_size ? hit = p;
p += 1;
);
hit
);
function linearize(p,sz, slon, slat, elon, elat, rev) local(x) global()
(
rev ? ( x=slon; slon=elon; elon=x; x=slat; slat=elat; elat=x; );
elon = (elon - slon) / sz;
elat = (elat - slat) / sz;
loop(sz,
p[0] = slon;
p[1] = slat;
slon += elon;
slat += elat;
p += 2;
);
);
function make_lowpass(f filtsize filtpos) global() local(windowpos sincpos x)
(
x = 0;
loop(filtsize,
x == filtsize/2 ? (
f[x] = 1.0;
) : (
windowpos = 2 * x * $pi / filtsize;
sincpos = filtpos * $pi * (x - filtsize/2);
// blackman-harris * window
f[x] = (0.35875 - 0.48829 * cos(windowpos) + 0.14128 * cos(2*windowpos) - 0.01168 * cos(3*windowpos)) * sin(sincpos) / sincpos;
);
x+=1;
);
);
function lowpass() local(src sz i j lpf_pos v sx sy filt p) global(tab tabsz)
(
lpf_pos>0.001 ? lpf_pos *= 0.95 : lpf_pos = 0.9;
sz = 64;
src = tab+tabsz*2 + sz*4 + 1024;
filt = src + tabsz*2 + sz*4 + 1024;
make_lowpass(filt, sz, lpf_pos);
memcpy(src, tab, tabsz*2);
i = src;
j = src + tabsz*2;
loop(sz/2,
memcpy(i-2,i,2);
memcpy(j,j-2,2);
j+=2;
i-=2;
);
i = 0;
loop(tabsz,
tab[i*2] != 10000 ? (
p = j = sx = sy = 0;
loop(sz,
v = src[(i+j-sz/2)*2];
v != 10000 ? (
p += filt[j];
sx += v * filt[j];
sy += src[(i+j-sz/2)*2 + 1] * filt[j];
);
j+=1;
);
tab[i*2] = sx/p;
tab[i*2+1] = sy/p;
);
i+=1;
);
);
function do_file(srcfn, destfn) local(fp fpout p lat lon skipping) (
(fp = fopen(srcfn,"r")) > 0 ? (
destfn < 0 || (fpout = fopen(destfn,"w")) > 0 ? (
p = tab;
skipping = 0;
while (fgets(fp,#line)) (
match("%s<trkpt lat=\"%f\" lon=\"%f\">%s",#line,#lead,lat,lon,#trail) ? (
destfn < 0 ? ( tabsz+=1; v_lat.include(p[1] = -lat); v_lon.include(p[0] = lon);) :
( !(skipping = p[0] == 10000) ? fprintf(fpout,"%s<trkpt lat=\"%.7f\" lon=\"%.7f\">%s",#lead,-p[1],p[0],#trail); );
p += 2;
) : destfn >= 0 ? ( skipping ? ( match("*</trkpt>*",#line) ? skipping = 0; ) : fwrite(fpout,#line,0) );
);
destfn >= 0 ? fclose(fpout);
);
fclose(fp);
);
);
function run() (
mouse_wheel ? ( zoom_view(mouse_wheel < 0 ? 1.1 : 1/1.1); mouse_wheel = 0;);
(mouse_cap&1)? (
!(last_mouse_cap & 1) ? (
cap_mode >= 0 && (mouse_cap&4) ? (
tmp = hit_test(mouse_x,mouse_y,0);
tmp >= 0 ? (
tmp < cap_mode ? (
cap_cnt = cap_mode+cap_cnt - tmp;
cap_mode = tmp;
) : (
cap_cnt = max(cap_mode+cap_cnt, tmp) - cap_mode;
);
) : cap_mode = tmp;
) : (
cap_mode = hit_test(mouse_x,mouse_y,0);
cap_mode >= 0 ? (
cap_cnt = 1;
while (hit_test(mouse_x,mouse_y,cap_mode+cap_cnt) >= 0) ( cap_cnt += 1; );
);
);
cap_start_lon = v_lon.unscale(mouse_x/gfx_w);
cap_start_lat = v_lat.unscale(mouse_y/gfx_h);
) : cap_mode >= 0 ? (
cap_cnt > 1 && (mouse_cap&4) ? (
linearize(tab + cap_mode*2,cap_cnt, cap_start_lon, cap_start_lat,
v_lon.unscale(mouse_x/gfx_w), v_lat.unscale(mouse_y/gfx_h),
mouse_cap&8);
) : (
tab[cap_mode*2] = v_lon.unscale(mouse_x/gfx_w);
tab[cap_mode*2+1] = v_lat.unscale(mouse_y/gfx_h);
);
is_dirty = 1;
) : scroll_view(mouse_x-last_mouse_x,mouse_y-last_mouse_y);
) : (
(last_mouse_cap & 1) && (last_mouse_cap & 16) && cap_mode >= 0 ? (
tab[cap_mode*2] = 10000;
is_dirty = 1;
);
is_dirty ? ( do_file(argv[1], argv[2]); is_dirty = 0; );
);
last_mouse_cap = mouse_cap;
last_mouse_x = mouse_x;
last_mouse_y = mouse_y;
p = tab;
hadprev = dist = 0;
loop(tabsz,
p[0] != 10000 ? (
x = v_lon.scale(p[0])*gfx_w;
y = v_lat.scale(p[1])*gfx_h;
hadprev ? (
gfx_set(0,.5,.7);
gfx_line(v_lon.scale(llon)*gfx_w,v_lat.scale(llat)*gfx_h,x,y);
dist += sqrt(sqr((p[0] - llon) * cos(llat*$pi/180.0)*69.172) + sqr((p[1] - llat)*60));
);
cap_mode == (p-tab)/2 ? gfx_set(1,0,1) : gfx_set(0,1,0);
gfx_circle(x,y,circle_size);
llon = p[0];
llat = p[1];
hadprev = 1;
);
p += 2;
);
gfx_x=gfx_y=0;
gfx_set(1,1,0);
gfx_printf("distance (approx) %.2f mi\n",dist);
gfx_update();
c = gfx_getchar();
c == 'l' ? ( lowpass(); is_dirty = 1; );
c >= 0 && c != 27 ? defer("run()");
);
argc < 2 ? printf("Usage: %s file.gpx output.gpx\n",argv[0]) : (
v_lat.min = v_lon.min = 100000;
v_lat.max = v_lon.max = -100000;
do_file(argv[1],-1);
tabsz > 0 ? (
zoom_view(1.3);
gfx_init("gpx edit",1024,768);
defer("run()");
) : printf("Error: %s has no <trkpt lines matching\n",argv[1]);
);

View File

@@ -0,0 +1,180 @@
// asynchronous HTTP server in EEL
function httpd.init(port, maxcon, table, stringoffs, wwwroot) global()
(
this.maxcon = maxcon;
this.tab = table;
this.port = port;
this.stringtab = stringoffs;
this.string_recsz = 2;
this.recsz = 3;
#this.wwwroot = wwwroot;
);
function httpd.getrecval(conid, parm) global()
(
conid >= 0 && conid < this.maxcon ? (
parm == 'sock' ? this.tab + conid*this.recsz + 0 : // socket
parm == 'st' ? this.tab + conid*this.recsz + 1 : // state
parm == 'fh' ? this.tab + conid*this.recsz + 2 : // file handle
0)
: 0
);
function httpd.set(conid, parm, value) local(x) global()
(
x = httpd.getrecval(conid,parm);
x>=0 ? x[]=value;
);
function httpd.get(conid, parm) local(x) global()
(
x=httpd.getrecval(conid,parm);
x>=0?x[];
);
function httpd.getbuf(conid, w) global()
(
conid >=0 && conid < this.maxcon ? this.stringtab + this.string_recsz*conid + w : -1;
);
function httpd.close(conid) global()
(
conid >=0 && conid < this.maxcon ?
(
tcp_close(httpd.get(conid,'sock'));
fclose(httpd.get(conid,'fh'));
httpd.set(conid,'sock',0);
httpd.set(conid,'fh',0);
);
);
function httpd.file_for_req(req, response) local(fn,fp) global() (
!strcmp(req,"") || !strcmp(req,"/") ? req = "/index.html";
str_getchar(req,0) == '/' &&
!match("*..*",req) &&
(fp=fopen(fn = strcat(#=#this.wwwroot,req),"rb")) > 0 ?
(
fseek(fp,0,1);
printf("GET %s -- 200: %s\n",req,fn);
strcat(response,sprintf(#, "HTTP/1.1 200 OK\r\n"
"Content-length: %d\r\n"
"Content-type: text/html\r\n"
"\r\n",
ftell(fp)));
fseek(fp,0,-1);
fp;
) : (
printf("GET %s -- 404\n",req);
fn = "The file specified could not be found.";
strcat(response,sprintf(#, "HTTP/1.1 404 NOT FOUND\r\n"
"Content-length: %d\r\n"
"Content-type: text/plain\r\n"
"\r\n"
"%s", strlen(fn),fn));
0;
);
);
// run input and output buffers
function httpd.runcon(idx) local(sock,x,str,rv,buffers) global() (
rv=0;
sock = httpd.get(idx,'sock');
sock > 0 ?
(
x=tcp_recv(sock,str=#);
x<0 ? (
httpd.close(idx);
) : (
buffers=httpd.getbuf(idx,0);
x>0 ? strcat(buffers,str);
rv+=x;
strlen(buffers+1)>0 ?
(
(x=tcp_send(sock,buffers+1)) > 0 ?
(
rv+=1;
str_delsub(buffers+1.1,0,x);
);
);
);
);
rv;
);
function httpd.run() local(sock, x, i, str, rv, t,hdrs,httpdver) global() (
str=#;
hdrs=#;
rv=0;
sock=tcp_listen(this.port,"",str);
sock > 0 ?
(
i=0;
while (i < this.maxcon && httpd.get(i,'sock')) ( i += 1; );
i < this.maxcon ? (
tcp_set_block(sock,0);
httpd.set(i,'sock',sock);
httpd.set(i,'st',0);
x=0;
loop(this.string_recsz, strcpy(httpd.getbuf(i,x), ""); x+=1; );
printf("httpd.run(): connection from '%s'\n",str);
rv+=1;
) : (
printf("httpd.run(): dropping connect from '%s', slots full\n",str);
tcp_close(x);
);
);
i=0;
while (i < this.maxcon)
(
this.httpd.runcon(i) ?
(
t = httpd.getbuf(i,0);
this.httpd.get(i,'st') == 0 ?
(
match("GET %S HTTP/1.%1d%S",t,str,httpdver,hdrs) &&
str_getchar(hdrs,0)=='\r' && str_getchar(hdrs,1)=='\n' &&
!strcmp(strcpy_substr(#,hdrs,-4),"\r\n\r\n")
?
(
httpd.set(i,'st',1 |
((httpdver==0 || matchi("\r\nConnection:*close\r\n",hdrs))?2:0)
);
httpd.set(i,'fh',httpd.file_for_req(str,t+1));
);
);
httpd.get(i,'fh') && !strlen(t+1) ? fread(httpd.get(i,'fh'),t+1,4096);
httpd.get(i,'st') == 3 ? (
strlen(t+1) == 0 ? (
httpd.close(i);
printf("sent data, closing\n");
);
);
rv+=1;
);
i+=1;
);
rv;
);
argc != 3 || strlen(argv[1])<1 || !match("%d",argv[2],port) ? (
printf("Usage: \n\t%s www_root port\n",argv[0]);
) : (
srv.httpd.init(port, 100, 100000, 10000, argv[1]);
// string [conidx] = send buffe
while(1)
(
srv.httpd.run() || Sleep(10);
);
);

View File

@@ -0,0 +1,10 @@
<? x=37; ?>
<? printf("y=%d;",x); ?>
<? _suppress += 1; ?>
printf("this will not get compiled\n");
<? _suppress -= 1; ?>
printf("apparently y is now %d but x is %d\n",y,x);

View File

@@ -0,0 +1,17 @@
width = 80;
lx=-1;
loop(1000000,
x = ((1+sin(pos))*0.5 * width)|0;
lx >= -1 && lx!=x ? (
loop(min(x,lx), printf(" "));
loop(abs(x-lx), printf("*"));
loop(width-max(x,lx), printf(" "));
) : (
loop(x, printf(" "));
printf("*");
loop(width-1-x, printf(" "));
);
lx=x;
printf("\n");
pos += 0.25 + sin(pos*0.32)*0.2;
);

View File

@@ -0,0 +1,73 @@
gfx_init("space",640,480);
function enemylist.init(buf, rows, cols, maxwid) global()
(
this.buf = buf;
this.rows=rows;
this.cols=cols;
this.maxwid = maxwid;
loop(rows*cols, buf[]=1; buf += 1; );
);
function enemylist.draw(pos, vpos, destextent*)
local(rad,buf,xpos,ypos,dxpos)
global(gfx_w,gfx_h,gfx_r,gfx_g,gfx_b,gfx_a)
(
gfx_r=gfx_a=1;
gfx_g=gfx_b=0;
dxpos = this.maxwid/this.cols*gfx_w;
buf=this.buf;
rad = dxpos*0.3;
destextent.right = 0;
destextent.bottom = 0;
destextent.left=2^20;
destextent.top=2^20;
ypos=dxpos*0.5 + gfx_h*vpos;
loop(this.rows,
xpos=pos*gfx_w + dxpos*0.5;
loop(this.cols,
buf[] ? (
destextent.left = min(destextent.left,xpos-rad);
destextent.right = max(destextent.right,xpos+rad);
destextent.top = min(destextent.top,ypos-rad);
destextent.bottom = max(destextent.bottom,ypos+rad);
gfx_circle(xpos,ypos,rad);
);
xpos += dxpos;
buf += 1;
);
ypos += dxpos;
);
);
enemylist.init(0, 4, 8, 0.8);
last_time = time_precise();
enemy_pos = 0;
enemy_vpos = 0;
enemy_vel = 0.05;
while ((curchar = gfx_getchar()) != 27)
(
now = time_precise();
enemylist.draw(enemy_pos, enemy_vpos, area);
enemy_vel > 0 ? (
area.right >= gfx_w ? ( enemy_vel = -enemy_vel; enemy_vpos += abs(enemy_vel); enemy_vel *= 1.3; );
) : (
area.left <= 0 ? ( enemy_vel = -enemy_vel; enemy_vpos += abs(enemy_vel); enemy_vel *= 1.3; );
);
enemy_pos += (now-last_time)*enemy_vel;
last_time = now;
sleep(33);
gfx_update();
);

View File

@@ -0,0 +1,22 @@
sum=0;
a= 1;
b = .1;
c= .2;
d = .5;
e = 4;
f = -0.2;
g = 0.3;
h = .37;
loop(62000,
i = 0;
sum=0.0;
loop(8192,
sum += i*(3+ a * b + c*d + e * (f - b*(-c) + g*(e-g*(-g)*g)) );
sum2 += (a*b)+(a*b)+((a*b)*((b*c)*((h*i)*(f*g))));
i += 0.001;
i2+=1;
);
);
printf("sum error %.18f %.18f\n", sum - 245333.476966294896556064, sum2 - 101488440.519564077258110046);
printf("sum error per inst %.18f %.18f\n", (sum - 245333.476966294896556064) / i, (sum2 - 101488440.519564077258110046)/i2);

View File

@@ -0,0 +1,35 @@
v1 = 2^50;
v2 = 2^50;
z=0;
(floor(v1)/v2) !== 1 ? printf("fail test floor\n");
(floor(v1)/(2^50)) !== 1 ? printf("fail test floor/const\n");
(floor(2^50)/v2) !== 1 ? printf("fail test floor-const\n");
(floor(2^50)/(2^50)) !== 1 ? printf("fail test floor-const/const\n");
(floor(v1+1)/(v2+1)) !== 1 ? printf("fail test floor+1\n");
(floor(v1+1)/(2^50+1)) !== 1 ? printf("fail test floor+1/const\n");
(floor(2^50 + 1)/(v2+1)) !== 1 ? printf("fail test floor-const+1");
(floor(2^50 + 1)/(2^50 + 1)) !== 1 ? printf("fail test floor-const+1/const\n");
((v1|0)/v2) !== 1 ? printf("fail test |0\n");
((v1|0)/(2^50)) !== 1 ? printf("fail test |0/const\n");
(((2^50)|0)/v2) !== 1 ? printf("fail test const|0\n");
(((2^50)|0)/(2^50)) !== 1 ? printf("fail test const|0/const\n");
((v1|1)/(v2+1)) !== 1 ? printf("fail test |1\n");
((v1|1)/(2^50+1)) !== 1 ? printf("fail test |1/const\n");
(((2^50)|1)/(v2 + 1)) !== 1 ? printf("fail test const|1\n");
(((2^50)|1)/(2^50 + 1)) !== 1 ? printf("fail test const|1/const\n");
((v1~1)/(v2+1)) !== 1 ? printf("fail test ~1\n");
((v1~1)/(2^50+1)) !== 1 ? printf("fail test ~1/const\n");
(((2^50)~1)/(v2 + 1)) !== 1 ? printf("fail test const~1\n");
(((2^50)~1)/(2^50 + 1)) !== 1 ? printf("fail test const~1/const\n");
c = v1; c |= v1;
c !== v1 ? printf("fail test |= \n");
c = v1; c |= 0;
c !== v1 ? printf("fail test |= 0\n");
c = v1; c &= v1;
c !== v1 ? printf("fail test &=\n");
c = v1; c ~= z;
c !== v1 ? printf("fail test ~= \n");