#include #include #include #include "abuf.h" double *samples; int n, max, frame; enum { Fps = 25, Srate = 48000, }; void eresized(int new) { if(new && getwindow(display, Refnone) < 0) sysfatal("can't reattach to window"); frame = Srate / Fps; max = Dx(screen->r); n = 0; samples = realloc(samples, sizeof(*samples * frame)); } void drawframe(void) { Point a, b; int i, x, y, h; draw(screen, screen->r, display->white, nil, ZP); x = screen->r.min.x; y = screen->r.min.y; h = Dy(screen->r); for(i=0; iblack, ZP); } flushimage(display, 1); } Abuf ain, aout; void main(int argc, char *argv[]) { double s; if(initdraw(nil, nil, "oscope") < 0) sysfatal("initdraw: %r"); eresized(0); ainit(&ain, 0); ainit(&aout, 1); while(agetd(&ain, &s) == 1){ if(n >= frame){ drawframe(); n = 0; } if(n < max) samples[n] = s; n++; aputd(&aout, s); } exits(0); }