{$N+} Program Scope; {This program is designed to record and plot the sound from a musical instrument} Uses Crt, Dos, graph; type values = array[1..30000] of byte; fitpar = array[1..8] of real; Var xx, yy, xxyy, xx2 :fitpar; dataf,inf :text; xl,xh :values; volt, xscale :real; cinit,cfin,npts,i,ch, startc,ii, jj,ci,cf,ctot,inet :integer; ttest, a1,b1,voltave,p,hcomp,phase, plength, scale :real; graphdriver, graphmode, error: integer; range,maxx, maxy,nr, nx,ny,nper, vint :integer; stop, fullstop :boolean; s1, s2, filename :string; xk : char; procedure graphwave; begin line(0,0,0,maxy); line(0,trunc(maxy/2),maxx,trunc(maxy/2)); for i:=1 to 320 do begin jj:=startc+i; volt:=(xh[jj] - 127.0); ny:=trunc(maxy/2-volt*maxy/2.0/127.0*xscale); nx:=i*2; putpixel(nx,ny,15); end; str(startc:10,s1); outtextxy(10,400,'The initial channel is '+s1); outtextxy(10,maxy-30,'Type w to save waveform to a file'); outtextxy(10,maxy-20,'You will need to know the starting and ending channels'); end; Procedure writedat; begin writeln('input the starting channel and ending channels'); readln(ci,cf); assign(inf,filename); rewrite(inf); for jj:=ci to cf do begin volt:=(xh[jj] - 127.0); writeln(inf,volt:6:2); end; end; procedure menus; begin closegraph; writeln(' Sound Analysis Program'); writeln; writeln(' key function'); writeln; writeln(' Page Up moves wave forward 1/4 screen (80) '); writeln(' Page Down moves wave backward 1/4 screen (-80) '); writeln(' -> moves wave forward 1 unit'); writeln(' <- moves wave backward 1 unit'); writeln; writeln(' w writes the waveform to a data file'); writeln; writeln(' q quit'); writeln; writeln(' Hit return when you are ready to record the sound.'); writeln(' The sound will be recorded for around 1 1/2 seconds and'); writeln(' then the waveform will be displayed on the screen.'); writeln(' Use the keys above to examine the waveform'); readln; initgraph(graphdriver,graphmode,''); maxx:=getmaxx; maxy:=getmaxy; end; Procedure Menu; begin writeln; writeln('Type g if you want to record at the fastest rate'); writeln(' and freeze the data'); writeln('Type l if you want live time run'); writeln('Type m to see this menu'); writeln('Type q at any time if you want to quit'); end; Procedure Fastget; Begin graphdriver:=detect; initgraph(graphdriver,graphmode,''); maxx:=getmaxx; maxy:=getmaxy; menus; i:=1; ttest:=0.0; port[$226]:=1; delay(3); port[$226]:=0; delay(1000); for i:=1 to 30000 do begin port[$22c]:=32; {Initiate the A/D conversion} while port[$22e]<128 do; {Check to see if the A/D is done} xh[i]:=port[$22a]; {write the high bytes to an array} end; startc:=0; scale:=1.0; graphwave; stop:=false; repeat if keypressed then begin xk:=readkey; if (ord(xk)=0) then begin xk:=readkey; case ord(xk) of 75 : begin startc:=startc-1; cleardevice; if startc<0 then startc:=1; graphwave; end; 77 : begin startc:=startc+1; cleardevice; graphwave; end; 73 : begin startc:=startc+80; cleardevice; if startc>29680 then startc:=1; graphwave; end; 81 : begin startc:=startc-80; cleardevice; if startc<0 then startc:=1; graphwave; end; 72 : begin xscale:=xscale*2.0; cleardevice; graphwave; end; 80 : begin xscale:=xscale/2.0; cleardevice; graphwave; end; end; end; if (ord(xk)<>0) then begin case xk of 'w' :begin closegraph; writeln('input the name of the data file:'); readln(filename); writedat; graphdriver:=detect; initgraph(graphdriver,graphmode,''); graphwave; end; 'q' : stop:=true; end; {case} end; end; {if} until stop; cleardevice; end; Procedure liverun; Begin graphdriver:=detect; initgraph(graphdriver,graphmode,''); maxx:=getmaxx; maxy:=getmaxy; i:=1; ttest:=0.0; port[$226]:=1; delay(3); port[$226]:=0; delay(1000); i:=0; repeat begin port[$22c]:=32; {Initiate the A/D conversion} while port[$22e]<128 do; {Check to see if the A/D is done} volt:=port[$22a]-127.0; {write the high bytes to an array} ny:=trunc(maxy/2-volt*maxy/2.0/127.0); nx:=i; delay(nr); putpixel(nx,ny,15); i:=i+1; if i>maxx then begin i:=0; cleardevice; end; end; until keypressed; end; Procedure freeze; begin graphdriver:=detect; initgraph(graphdriver,graphmode,''); maxx:=getmaxx; maxy:=getmaxy; i:=1; ttest:=0.0; port[$226]:=1; delay(3); port[$226]:=0; delay(1000); For i:=1 to maxx do begin port[$22c]:=32; {Initiate the A/D conversion} while port[$22e]<128 do; {Check to see if the A/D is done} volt:=port[$22a]-127.0; {write the high bytes to an array} ny:=trunc(maxy/2-volt*maxy/2.0/127.0); nx:=i; delay(nr); putpixel(nx,ny,15); end; repeat until keypressed; end; begin menu; xscale:=1.0; nr:=0; fullstop := false; repeat if keypressed then begin case readkey of 'g': begin fastget; closegraph; menu; end; 'l': begin nr:=0; liverun; closegraph; menu; end; 'f': begin freeze; closegraph; end; 'm' : menu; 'q': fullstop:=true; end; {case} end; {if} until fullstop; end. {main program}