// ZPlane Viewer for ResoLab1 (one biquad) // Original code, 1988-1991, in Objective C for NeXTStep // This port to Open GL, 2005 #include #include #include #include #include #include #include char file_name[256]; #define X_MAX 640.0 #define Y_MAX 180.0 #define PI 3.141592654782 #define SQRT_TWO 1.414213562 #define TWO_PI 6.283185309564 #define SRATE 44100.0 int numStrings = 0; int notDone = 1; int outOne = 0; char **inputString; int myWin; // The input command pipe and socket threads are defined here. #include "threads.h" unsigned long string_thread; float params[4] = {0.0, 0.0, 0.0, 0.0}; float incoeffs[2],outcoeffs[2]; #define STRING_LEN 1024 #define MAX_IN_STRINGS 64 void newStringByPipe(void) { extern int numStrings, notDone; extern char **inputString; int i,gotOne; // Malloc inputString. inputString = (char **) malloc(MAX_IN_STRINGS * sizeof(char *)); for ( i=0;i 0) { if (inputString[outOne][0] == '/') { printf(inputString[outOne]); fflush(stdout); } else { sscanf(inputString[outOne],"%f %f %f %f\n", ¶ms[0],¶ms[1],¶ms[2],¶ms[3]); gotOne = 1; } outOne += 1; if (outOne == MAX_IN_STRINGS) outOne = 0; numStrings -= 1; } if (gotOne) { glutSetWindow(myWin); glutPostRedisplay(); } } } // Free inputString. for ( i=0;i 0.01) { tempx *= 0.25; zex(xcen+0.75+tempx,ycen+tempy,0.02); zex(xcen+0.75+tempx,ycen-tempy,0.02); } temprad = rad * params[3]; // Zeroes tempx = temprad * cos(params[2]/SRATE*TWO_PI); tempy = 0.9 * temprad * sin(params[2]/SRATE*TWO_PI); incoeffs[0] = -params[3]*2*sin(params[2]/SRATE*TWO_PI); incoeffs[1] = params[3]*params[3]; if (temprad > 0.01) { tempx *= 0.25; zero(xcen+0.75+tempx,ycen+tempy,0.03); zero(xcen+0.75+tempx,ycen-tempy,0.03); } if (params[2]==-1 && params[3]==-1) { zero(xcen+0.95,ycen,0.03); zero(xcen+0.55,ycen,0.03); incoeffs[0] = 0; incoeffs[1] = -1.0; } } #define MAXLENGTH 1024 void doNDrawWaveAndSpectrum() { float xl=-0.99,yl=0.5; float delx = 1.5 / (float) MAXLENGTH; float xr=xl+delx,yr=0.5; int i; float impulse[MAXLENGTH]; float in=0.0,out=0.0,ins[2]={0.0,0.0},outs[2]={0.0,0.0}; in = 1.0; glBegin(GL_LINES); for (i=0;i 1) { if (av[1][1]=='s') scale = atof(av[2]); else { printf("useage: ZViewGL [-s scale]\n"); exit(0); } } glutInit(&ac, av); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); strcpy(titleString,"OS X GL ZPlane Viewer"); glutInitWindowSize(X_MAX*scale,Y_MAX*scale); glutInitWindowPosition(730,70); myWin = glutCreateWindow(titleString); glutDisplayFunc(display); glutKeyboardFunc(KeyFunc); glutSpecialFunc(SpecialFunc); glutIdleFunc(IdleStub); glutWMCloseFunc(die); glColor4f(0, 0, 0, 0); init(); setbuf(stdin,NULL); startPipeThread(); for (i=0;i<=33;i++) { sine[i] = (float) sin(TWO_PI * (double) i / 32.0); cosine[i] = (float) cos(TWO_PI * (double) i / 32.0); } glutMainLoop(); return 0; }