home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
d
/
dir_nm20.zip
/
Dir_NM_2.0
/
NM-Sound.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-07-16
|
9KB
|
296 lines
/* === NM-Sound.c ===
*
* void Ball(p,q,Draw)
* void Sound(ch)
*
*/
#include "NM.h"
void Ball(p,q,Draw)
int p,q,Draw;
{
if (Draw==1) { SetColor("white");DrawEllipse(p,q,8,8,0,360); }
else if (Draw==0) Rub(p-2,q-2,12,13,"MediumBlue");
}
void Sound(ch)
char ch;
{
int i,j,k,p,q,FORLIM;
XClearWindow(display,win);Use_Font("12x24");
switch (ch)
{
case 'I':if ((unifile=fopen("Dir_Song/IM.uit","r"))==NULL)
{
uniset[0][0]=1000;for (i=1;i<=10;i++) uniset[0][i]=0;
for (j=0;j<100;j++)
{
uniset[j][0]=1000;uniset[j][10]=32767;
for (i=1;i<=9;i++) uniset[j][i]=37;
}
contain=99;
}
lf=37;hf=32767;t=1000;
_LA:SetColor("green");
OutTextXY(420,50,"--- Sound-Imitation ---");
SetColor("white");DrawRectangle(20,138,1103,567);
Rub(22,140,1100,564,"MediumBlue");
Rub(100,818,900,27,"black");
SetColor("white");OutTextXY(26,116,"Fn=");
OutTextXY(457,116,"No.(1--100)=");
for (i=0;i<=9;i++) Line(i*100+122,696,i*100+122,704);
OutTextXY(26,744,"T(ms)");readat(610,116,3,&k);
if (k<1 || k>100)
{
k=1;Rub(610,92,60,27,"black");SetColor("green");
OutTextXY(610,116,"1");
}
SetColor("white");
_LE:lf=uniset[k-1][1];hf=lf;t=uniset[k-1][0];
for (i=1;i<11;i++)
{
if (uniset[k-1][i]<lf) lf=uniset[k-1][i];
if (uniset[k-1][i]>hf) hf=uniset[k-1][i];
}
_LB:Rub(22,140,1100,556,"MediumBlue");SetColor("white");
d=log((double)hf/lf)/100;
for (i=10;i>0;i--)
{
p=i*100+18;fn=uniset[k-1][i];
q=(int)floor(660-5*log((double)fn/lf)/d+0.5);
Ball(p,q,1);
}
SetColor("cyan");Out_I_XY(30,170,hf);Out_I_XY(30,670,lf);
Notice(p-2,677,13,13,1,"magenta","MediumBlue");
Rub(107,722,1000,26,"black");SetColor("gold");
for (i=1;i<11;i++)
Out_I_XY(i*100+10,744,(int)(0.1*t*i-0.1*t));
SetColor("green");
OutTextXY(300,841,"Esc -- Exit Return -- Go on A...Z -- sound");
Rub(610,92,60,27,"black");SetColor("green");
Out_I_XY(610,116,k);fn=uniset[k-1][1];uniset[k-1][0]=t;
Rub(70,92,80,27,"black");SetColor("green");
Out_I_XY(70,116,fn);
do {
ch=GetKey();
if (ch=='?' || ch=='@' || ch=='$' || ch=='^' || ch=='<'
|| ch=='>')
switch (ch)
{
case '?': /* Up */
case '@':Ball(p,q,0); /* Down */
switch (ch)
{
case '?':if (q>160) q-=2;else q=660;
break;
case '@':if (q<660) q+=2;else q=160;
break;
}
Ball(p,q,1);
fn=(int)floor(lf*exp(d*(660-q)/5)+0.5);
Rub(70,92,80,27,"black");
SetColor("green");Out_I_XY(70,116,fn);
uniset[k-1][(p-18)/100]=fn;
break;
case '$':if (k>1) k--;else k=100; /* PgUp */
goto _LE;
break;
case '^':if (k<100) k++;else k=1; /* PgDn */
goto _LE;
break;
case '<': /* Left */
case '>':Notice(p-2,677,13,13,0,"magenta",
"MediumBlue"); /* Right */
switch (ch)
{
case '<':if (p>118) p-=100;
else p=1018;
break;
case '>':if (p<1018) p+=100;
else p=118;
break;
}
fn=uniset[k-1][(p-18)/100];
Notice(p-2,677,13,13,1,"magenta",
"MediumBlue");
q=(int)floor(660-5*log((double)fn/lf)/d+
0.5);
Ball(p,q,1);Rub(70,92,80,27,"black");
SetColor("green");Out_I_XY(70,116,fn);
break;
}
else if (ch==' ' || isalpha(ch))
{
if (uniset[k-1][0] < 0)
{
x=0;
do {
for (j=1;j<=10;j++)
{ /* sound(uniset[k-1][j]);
delay(1); */
}
x+=10;
} while (x+uniset[k-1][0]<=-10);
}
else
{
for (j=1;j<=10;j++)
{
/* sound(uniset[k-1][j]);
delay((int)floor(0.1*
uniset[k-1][0]+0.5));
*/
}
}
/* nosound(); */
}
} while (ch != '!' && ch != '&');
if (ch != '&')
{
Rub(100,820,960,27,"black");SetColor("white");
OutTextXY(450,800,"C--correct,G--go on");ch=GetKey();
if (ch=='!') ch='G';Rub(20,770,1070,90,"black");
if (ch=='C')
{
SetColor("white");
OutTextXY(450,830,"Change scale (Y/N) ?");
ch=GetKey();Rub(20,805,1070,27,"black");
if (ch=='Y')
{
SetColor("cyan");OutTextXY(204,830,"Lf=");
readat(260,830,5,&lf);
if (lf<19)
{
lf=19;Rub(260,805,80,27,"black");
SetColor("green");Out_I_XY(260,830,lf);
}
else
{
for (i=1;i<=10;i++)
{
if (lf>uniset[k-1][i])
{
lf=uniset[k-1][i];
Rub(260,805,80,27,"black");
SetColor("green");
Out_I_XY(260,830,lf);
}
}
}
SetColor("cyan");OutTextXY(456,830,"Hf=");
readat(510,830,5,&hf);
if (hf>32767)
{
hf=32767;Rub(510,805,100,27,"black");
SetColor("green");Out_I_XY(510,830,hf);
}
else
{
for (i=1;i<=10;i++)
{
if (hf<uniset[k-1][i])
{
hf=uniset[k-1][i];
Rub(510,805,100,27,"black");
SetColor("green");
Out_I_XY(510,830,hf);
}
}
}
fn=lf;SetColor("cyan");
OutTextXY(696,830,"T( <0 repeat )=");
readat(890,830,5,&t);Rub(10,805,1000,27,"black");
if (abs(t)<10) t=10;
}
goto _LB;
}
else if (ch=='G')
{
SetColor("white");
OutTextXY(410,840,"Input new unit (Y/N) ?");
ch=GetKey();
if (ch=='Y')
{
Rub(70,92,80,27,"black");
Rub(610,92,60,27,"black");goto _LA;
}
}
}
unifile=fopen("Dir_Song/IM.uit","w");
if (unifile!=NULL) rewind(unifile);else timfile=tmpfile();
for (j=0;j<100;j++)
for (i=0;i<11;i++) fwrite(&uniset[j][i],sizeof(int),1,unifile);
if (unifile != NULL) fclose(unifile);unifile=NULL;
break;
/* I */
case 'O':printf("Print out (Y/N) ?");ch=GetKey();putchar('\n');
switch (ch)
{
case 'Y':FORLIM=contain;
for (i=1;i<FORLIM;i++)
{
fprintf(stdout,"%2ld.Tm=%5ld(ms) F=",i,
uniset[i][0]);
for (j=1;j<=10;j++)
fprintf(stdout,"%6ld",uniset[i][j]);
putc('\n',stdout);
}
break;
default:FORLIM=contain;
for (i=1;i<FORLIM;i++)
{
if (i==25 || i==49 || i==73 || i==97)
{
printf(" Return key to go on ...");
scanf("%*[^\n]");
}
printf("%2ld.Time=%4ld(ms) F=",i,uniset[i][0]);
for (j=2;j<=11;j++)
{ printf("%12ld",uniset[i][j-1]); }
putchar('\n');
}
break;
}/*case*/
putchar('\n');printf("Press any key to Menu\n");
do { } while (!(ch=GetKey()));
break;
/* L */
case 'S':XClearWindow(display,win);p=0;q=contain;
printf("Esc--exit Return--repeat\n\n");
printf("Unit number: From---");scanf("%ld", &p);
printf("To---");scanf("%ld",&q);k=p;printf("Number=");
do {
printf("%12ld", k);
if (uniset[k][0] < 0)
{
x=0;
do {
for (j=1;j<=10;j++)
{ /* sound(uniset[k][j]);delay(1); */ }
x+=10;
} while (x+uniset[k][0]<=-10);
}
else
{
for (j=1;j<=10;j++)
{
if (k!=0) { /* sound(uniset[k][j]); */ }
/* delay((int)floor(0.1*uniset[k][0]+0.5)); */
}
}
if (k != 0) { /* nosound(); */ }
/* delay(1000); */
if ((ch=GetKey())!=NULL)
switch (ch)
{
case '&':return;break;
case '!':k--;break;
}
k++;
} while (k<=q);
break;
}/* case */
} /* S_I */