📄 fft.c
字号:
/* settup graphics mode */
registerbgidriver(CGA_driver);
registerbgidriver(EGAVGA_driver);
initgraph(&GraphDriver, &GraphMode, "");
if (graphresult() != grOk) {
fprintf(stderr, "fft: %s\n", grapherrormsg(graphresult()));
exit(1);
}
if ((i_size = getgraphmode()) != CGAHI)
setbkcolor(BLACK);
switch (i_size) {
case CGAHI:
Primary = WHITE;
Cursor = WHITE;
Length = 100.0;
Bottom = 150;
break;
case EGAHI:
Primary = LIGHTGRAY;
Cursor = LIGHTGREEN;
Length = 250.0;
Bottom = 300;
break;
case VGAHI:
Primary = LIGHTGRAY;
Cursor = LIGHTGREEN;
Length = 380.0;
Bottom = 430;
}
setcolor(Primary);
setfillstyle(SOLID_FILL, Primary);
settextjustify(LEFT_TEXT, TOP_TEXT);
settextstyle(DEFAULT_FONT, HORIZ_DIR, 2);
cleardevice();
outtextxy(TEXTX, TEXTY, "Computing FFT");
/* Draw ruler line */
line(LEFT, Bottom + 5, RIGHT, Bottom + 5);
for (i_size = LEFT; i_size <= RIGHT ; i_size += 10) {
line(i_size, Bottom + 5, i_size, Bottom + 10);
line(i_size + 1, Bottom + 5, i_size + 1, Bottom + 10);
}
/* create under-cursor memory */
i_size = imagesize(LEFT, TOP, LEFT + 1, Bottom);
Save = malloc(i_size);
}
void commands()
{
int key, filter;
char string[4];
setcolor(BLACK); /* erase text */
outtextxy(TEXTX, TEXTY, "Computing FFT");
setcolor(Primary);
Left = 320;
filter = 128;
strcpy(string, "128");
outtextxy(TEXTX, TEXTY, "Filter # 128");
getimage(Left, TOP, Left + 1, Bottom, Save);
setfillstyle(SOLID_FILL, Cursor);
bar(Left, TOP, Left + 1, Bottom);
for (;;) {
while (bioskey(1) == 0) /* wait for key press */
;
key = getkey();
switch(key) { /* find out which key was pressed */
case HOMEKEY:
j1: putimage(Left, TOP, Save, COPY_PUT);
filter = 0;
Left = LEFT;
getimage(Left, TOP, Left + 1, Bottom, Save);
bar(Left, TOP, Left + 1, Bottom);
setcolor(BLACK); /* erase old text */
outtextxy(TEXTXN, TEXTY, string);
setcolor(Primary);
sprintf(string, "%d", filter);
outtextxy(TEXTXN, TEXTY, string);
break;
case ENDKEY:
j2: putimage(Left, TOP, Save, COPY_PUT);
filter = 255;
Left = RIGHT - 1;
getimage(Left, TOP, Left + 1, Bottom, Save);
bar(Left, TOP, Left + 1, Bottom);
setcolor(BLACK); /* erase old text */
outtextxy(TEXTXN, TEXTY, string);
setcolor(Primary);
sprintf(string, "%d", filter);
outtextxy(TEXTXN, TEXTY, string);
break;
case CTRLLEFTKEY:
if (filter <= 9)
goto j1;
putimage(Left, TOP, Save, COPY_PUT);
Left -= 20;
filter -= 10;
getimage(Left, TOP, Left + 1, Bottom, Save);
bar(Left, TOP, Left + 1, Bottom);
setcolor(BLACK); /* erase old text */
outtextxy(TEXTXN, TEXTY, string);
setcolor(Primary);
sprintf(string, "%d", filter);
outtextxy(TEXTXN, TEXTY, string);
break;
case LEFTKEY:
if (filter <= 0) {
beep();
break;
}
putimage(Left, TOP, Save, COPY_PUT);
Left -= 2;
filter--;
getimage(Left, TOP, Left + 1, Bottom, Save);
bar(Left, TOP, Left + 1, Bottom);
setcolor(BLACK); /* erase old text */
outtextxy(TEXTXN, TEXTY, string);
setcolor(Primary);
sprintf(string, "%d", filter);
outtextxy(TEXTXN, TEXTY, string);
break;
case CTRLRIGHTKEY:
if (filter >= 245)
goto j2;
putimage(Left, TOP, Save, COPY_PUT);
Left += 20;
filter += 10;
getimage(Left, TOP, Left + 1, Bottom, Save);
bar(Left, TOP, Left + 1, Bottom);
setcolor(BLACK); /* erase old text */
outtextxy(TEXTXN, TEXTY, string);
setcolor(Primary);
sprintf(string, "%d", filter);
outtextxy(TEXTXN, TEXTY, string);
break;
case RIGHTKEY:
if (filter >= 255) {
beep();
break;
}
putimage(Left, TOP, Save, COPY_PUT);
Left += 2;
filter++;
getimage(Left, TOP, Left + 1, Bottom, Save);
bar(Left, TOP, Left + 1, Bottom);
setcolor(BLACK); /* erase old text */
outtextxy(TEXTXN, TEXTY, string);
setcolor(Primary);
sprintf(string, "%d", filter);
outtextxy(TEXTXN, TEXTY, string);
break;
case F1:
if (PrintScreen())
bee_bop();
break;
case ESC:
quit();
default:
beep();
}
}
}
void beep()
{
sound(200);
delay(125);
nosound();
}
void bee_bop()
{
sound(1000);
delay(80);
sound(200);
delay(160);
sound(1000);
nosound();
}
/*
* Return to MS-DOS operating system
*/
void quit()
{
sound(1000);
delay(250);
nosound();
closegraph();
free((char *)Save);
exit(0);
}
/*
* Dumps a screen to printer in Double Density landscape format.
* This routine is from the Borland Programming Forum on CompuServe.
*
* returns TRUE on error
*/
int PrintScreen()
{
int X,Y,YOfs;
int BitData,MaxBits;
unsigned int Height,Width;
struct viewporttype Vport;
getviewsettings(&Vport);
Width = Vport.bottom - Vport.top;
Height = (Vport.right + 1) - Vport.left;
if (PrintChar(27))
return (1);
if (PrintChar('3'))
return (1);
if (PrintChar(24)) /* 24/216 inch line spacing */
return (1);
Y = 0;
while (Y < Height) {
if (PrintChar(27))
return (1);
if (PrintChar('L')) /* Double Density */
return (1);
if (PrintChar(Width & 0xff))
return (1);
if (PrintChar(Width >> 8))
return (1);
for (X = Width - 1; X >= 0; X--) {
BitData = 0;
if ((Y + 7) <= Height)
MaxBits = 7;
else
MaxBits = Height - Y;
for (YOfs = 0; YOfs <= MaxBits; YOfs++) {
BitData = BitData << 1;
if (getpixel(YOfs + Y, X) > 0)
BitData++;
}
if (PrintChar(BitData))
return (1);
}
if (PrintChar('\r'))
return (1);
if (PrintChar('\n'))
return (1);
Y += 8;
}
PrintChar(12); /* formfeed */
return (0);
}
/*
* returns TRUE on error
*/
int PrintChar(out)
int out;
{
unsigned char ret;
ret = biosprint(0, out, 0);
if ((ret & 0x29) || !(ret & 0x10))
return 1;
else
return 0;
}
int getkey()
{
int key, lo, hi;
key = bioskey(0);
lo = key & 0x00FF;
hi = (key & 0xFF00) >> 8;
return((lo == 0) ? hi + 256 : lo);
}
/* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -