pie, Custom-*
NEXT-*
MENU ON:MENU 1,0,1:MENU 2,0,1-*
MENU 3,0,1:MENU 4,0,1-*
GOSUB ScreenSetup*
RETURN-*
A
SaveWave: -*
'Saves custom waveform data to disk.-*
MENU OFF:MENU 1,0,0:MENU 2,0,0-*
MENU 3,0,0:MENU 4,0,0-*
CLS:LOCATE 5,10-*
PRINT "* Press RETURN to exit *"-*
LOCATE 6,10:PRINT STRING? ( 24, "-")-*
LOCATE 8,10:PRINT "Enter filename to save:"-*
LOCATE 9,10:LINE INPUT ">> "; filename?-*
IF filename?="" THEN GOTO ExitSave ' Abort routine.-*
ON ERROR GOTO ErrorTrap-*
OPEN filename? FOR OUTPUT AS #1-*
LOCATE 11,10:PRINT "Saving under filename"-*
LOCATE 12,10: PRINT CHR? ( 34); filename? ; CHR? ( 34) ;"..."-*
FOR n=0 TO 255 'Output custom waveform array values...-*
WRITE #l,customform%(n)«*
NEXT-*
CLOSE #1:ON ERROR GOTO 0-*
pause&=TIMER 'Wait for disk drive to finish...-*
WHILE TIMER<pause&+6:WEND-*
saveflag=l 'Current custom waveform now saved.<
ExitSave:-*
MENU ON:MENU 1,0,1:MENU 2,0,1-*
MENU 3,0,1:MENU 4,0,1-*
GOSUB ScreenSetup-*
RETURN-*
<*
BASICwave:-*
'Converts custom waveform to BASIC subroutine.-*
MENU OFFrMENU 1,0,0:MENU 2,0,0-*
MENU 3,0,0:MENU 4,0,0-*
CLS:LOCATE 5,15-*
PRINT "* Press RETURN to exit *"-*
LOCATE 6,15:PRINT STRING$ ( 24, "-11):PRINT-*
PRINT "Enter output filename to create custom waveform routine:
4,
LINE INPUT ">> "; filename?-*
IF filename?="" THEN GOTO ExitBASICwave 'Abort routine.-*
ON ERROR GOTO ErrorTrap-*
OPEN filename? FOR OUTPUT AS #1-*
PRINT "Creating " ;CHR? (34) ; filename? ;CHR? ( 34) ;"..."-*
PRINT #1, ; filename?-*
FOR n=0 TO 255 STEP 8-*
PRINT #1,"DATA ";«
FOR nn=0 TO 7-*
PRINT #1,USING "+###" ;waveform%(7,n+nn) ;-*
IF nn<7 THEN PRINT fl,","y ELSE PRINT #1,""-*
NEXT nn-*
NEXT n-*
CLOSE #1:ON ERROR GOTO 0-*
pause&=TIMER 'Wait for disk drive to finish...-*
WHILE TIMER<pause&+6:WEND-*
PRINT:PRINT "FINIS.11-*
pause&=TIMER: WHILE TIMER<pause&+2 : WEND-*
ExitBASICwave:-*
MENU ON:MENU 1,0,1:MENU 2,0,1-*
MENU 3,0,1:MENU 4,0,1-*
GOSUB ScreenSetup-*
RETURN-*
Quit:*
'Exits program to Amiga BASIC.«
MENU OFF:MENU 1,0,0:MENU 2,0,0-*
MENU 3,0,0:MENU 4,0,0-*
msgl?="Quit program to BASIC?"-*
IF saveflag=0 THEN-*
msg2?="(Custom waveform is NOT saved.)"*
ELSE-*
msg2?=""-*
END IF-*
CALL Requester (msgl?,msg2? , "QUIT" , "CANCEL" , 2,answer%)-*
IF answer%=0 THEN 'CANCEL was selected.-*
MENU ON:MENU 1,0,1:MENU 2,0,1-*
MENU 3,0,1:MENU 4,0,1-*
MENU 2,5,voice(0):MENU 2,6,voice(1)*
MENU 2,7,voice(2):MENU 2,8,voice(3)*
RETURN*
4,
PickWave:*
1 Picks waveforms for voices.*
GOSUB WavescreenSetup*
WaveLoop:*
WHILE MOUSE(0)=0:WEND:mx=MOUSE(1):my=MOUSE(2)*
IF mx>21 AND mx<99 AND my>108 AND my<132 THEN*
LINE (23,109)-(98,131),l,bf 'Flash exit button.*
WHILE MOUSE(0)<>0:WEND 'Wait for mouse button release.*
GOTO ExitWave*
ELSEIF mx>8 AND mx<90 AND my>25 AND my<35 THEN*
WHILE MOUSE(0)<>0:WEND 'Wait for mouse button release.*
v=0:wform(0)=menuitem *Set choice of new waveform.*
ON menuitem GOSUB Sine,Square,Triangle,Sawtoothl,Sawtooth2,Multi pie,Custom*
LOCATE 4,12:PRINT waveform$(menuitem);SPACE?(5)*
ELSEIF mx>8 AND mx<90 AND my>43 AND my<53 THEN*
WHILE MOUSE(0)<>0:WEND 'Wait for mouse button release.*
v=l:wform(l)=menuitem 'Set choice of new waveform.*
ON menuitem GOSUB Sine,Square,Triangle,Sawtoothl,Sawtooth2,Multi pie,Custom*
LOCATE 6,12:PRINT waveform$(menuitem);SPACE§(5)*
ELSEIF mx>8 AND mx<90 AND my>61 AND my<71 THEN*
WHILE MOUSE(0)<>0:WEND 'Wait for mouse button release.*
v=2:wform(2)=menuitem 'Set choice of new waveform.*
ON menuitem GOSUB Sine,Square,Triangle,Sawtoothl,Sawtooth2,Multi pie,Custom*
LOCATE 8,12:PRINT waveform?(menuitem);SPACE$(5)*
ELSEIF mx>8 AND mx<90 AND my>79 AND my<89 THEN*
WHILE MOUSE(0)<>0:WEND 'Wait for mouse button release.*
v=3:wform(3)=menuitem 'Set choice of new waveform.*
ON menuitem GOSUB Sine,Square,Triangle,Sawtoothl,Sawtooth2,Multi pie,Custom*
LOCATE 10,12:PRINT waveform?(menuitem);SPACE?(5)*
END IF*
IF menuitem=7 THEN GOSUB DesignWave 'Design custom wave.*
GOTO WaveLoop*
ExitWave:*
IF customflag=l THEN GOSUB MakeWave 'Calculate custom wave.*
customflag=0*
GOSUB ScreenSetup*
MENU 1,0,1:MENU 2,0,1:MENU 3,0,1:MENU 4,0,1*
RETURN*
«
DesignWave:*
'Allows design of custom waveforms.*
IF mx>286 AND mx<544 AND my>27 AND my<157 THEN 'Wave box.*
IF customflag=0 THEN LINE (287,28)-(543,156),0,bf 'Erase.*
customflag=l 'Signals new custom waveform.*
saveflag=0 'Signals that new waveform is not yet saved.*
WHILE MOUSE(0)<>0*
mx2=M0USE(l):my2=MOUSE(2) 'Get new mouse coordinates.*
IF mx2>286 AND mx2<544 AND my2>27 AND my2<157 THEN*
LINE (mx,my)-(mx2,my2),3 'Draw rubber band line...*
LINE (mx,my)-(mx2,my2),0*
END IF*
WEND*
IF mx2>286 AND mx2<544 AND my2>27 AND my2<157 THEN*
LINE (mx,my)-(mx2,my2),3*
'Reads custom-designed waveform off screen.*
FOR n=0 TO 255*
LOCATE 19,8*
PRINT "Processing waveform data. Please be patient: ;*
PRINT -n+255;SPACE$(2)*
y=29 'Starting point of vertical scan.*
pixel=0 'Pixel values to be read off screen.*
WHILE pixel=0 AND y<156*
pixel=POINT (n+287,y):y=y+l*
WEND*
customform%(n)=-(y-92)*2 'Put value in waveform array.*
waveform%(7,n)=customform%(n) "Copy to plotting array.*
NEXT*
FOR v=0 TO 3 'Update new waveform assignments to voices...*
ON wform(v) GOSUB Sine,Square,Triangle,Sawtoothl,Sawtooth2,Multi pie,Custom*
NEXT*
RETURN*
•4
Sine:*
'Sets selected voice to sine waveform.*
WAVE v,sineform%*
RETURN*
Square:*
'Sets selected voice to square waveform.*
WAVE v,squareform%*
RETURN*
Triangle:*
'Sets selected voice to triangle waveform.*
WAVE v,triform%*
RETURN*
*
Sawtoothl:*
'Sets selected voice to sawtoothl waveform.*
WAVE v,sawforml%*
RETURN*
*
Sawtooth2:*
'Sets selected voice to sawtooth2 waveform.*
WAVE v,sawform2%*
RETURN*
A
Multiple:*
'Sets selected voice to multiple-sine waveform.*
WAVE v,multiform%*
RETURN*
*
Custom:*
"Sets selected voice to custom waveform.*
WAVE v,customform%*
RETURN*
A
WavescreenSetup:*
'Sets up screen for waveform selections.*
CLS:MENU 1,0,0:MENU 2,0,0*
MENU 3,0,0:MENU 4,0,0*
LOCATE 19,30:PRINT "Waveform: "+waveform$(menuitem)*
LINE (286,27)-(544,157),2,b 'Draw waveform box.*
FOR n=l TO 254 STEP 2 'Plot waveform on screen...*
xl=n-l+287:yl=-waveform%(menuitem,n-l)/2+92*
x2=n+l+287:y2=-waveform%(menuitem,n+1)/2+92*
LINE (xl,yl)-(x2,y2),3*
NEXT*
LOCATE 4,2:PRINT "Voice 0:";SPACE?(2);waveform$(wform(0))*
LINE (8,25)-(90,35),2,b 'Draw voice 0 button.*
LOCATE 6,2:PRINT "Voice 1:";SPACE?(2);waveform?(wform(1))*
LINE (8,43)-(90,53),2,b 'Draw voice 1 button.*
LOCATE 8,2:PRINT "Voice 2:";SPACE?(2);waveform?(wform(2))*
LINE (8#61)-(90,71),2,b 'Draw voice 2 button.*
LOCATE 10,2:PRINT "Voice 3:";SPACE?(2);waveform?(wform(3))*
LINE (8,79)-(90,89),2,b 'Draw voice 3 button.*
LOCATE 14,5:PRINT "EXIT"*
LINE (25,110)-(95,130),3,b 'Draw exit button.*
LINE (21,108)-(99,132),2,b*
RETURN*
*
FreqRange:*
'Adjusts range of Frequency sliders.*
MENU OFF:MENU 1,0,0:MENU 2,0,0*
MENU 3,0,0:MENU 4,0,0*
CLS*
LOCATE 5,7:PRINT "This selection lets you change"*
LOCATE 6,7*
PRINT "the lower and upper limits of the Frequency sliders."*
LOCATE 7,7*
PRINT "Default settings are 100 (lower) and 4000 (upper)."*
LOCATE 8,7*
PRINT "Current settings are";lofreq;"(lower) and";hifreq;"(upper )."«
LOCATE 9,7:PRINT "Allowable range is 0 to 15000."*
LOCATE 11,7*
PRINT "Press RETURN below to exit..."*
LOCATE 12,7:PRINT "Or enter new limits and press RETURN."*
LOCATE 14,7:LINE INPUT "Lower limit >> ";lotemp?*
IF lotemp?="" THEN Exitfreq*
lotemp=VAL(lotemp?)*
IF lotemp>14999 OR lotemp<0 THEN FreqRange*
LOCATE 16,7:LINE INPUT "Upper limit >> ";hitemp?*
IF hitemp?="" THEN Exitfreq*
hitemp=VAL(hitemp?)*
IF hitemp>15000 OR hitemp<=lotemp THEN FreqRange*
lofreq=lotemp:hifreq=hitemp 'Set changes.-*
freqfactor=(hifreq-lofreq)/621 'New Frequency slider factor.-*
'Set new default frequencies:-*
FOR n=0 TO 3-*
frequency(n) = (hifreq-lofreq)/2+lofreq-*
slider(l,n) = ( frequency(n)-lofreq)/freqfactor+4-*
NEXT-*
Exitfreq:-*
GOSUB ScreenSetup*
MENU ON:MENU 1,0,1:MENU 2,0,1-*
MENU 3,0,1:MENU 4,0,1-*
IF voice(n) =2 THEN-*
SOUND frequency(n),duration(n),volume(n),n-*
'Traps common errors, mostly disk.-*
'Requires Requester window subprogram•<*
BEEP 'Get user's attention.-*
IF ERR=53 THEN-*
msgl$="ERROR NUMBER "+STR§ (ERR)-*
ExitError:*
'Abort operation or try again.*
msg2$=""*
CALL Requester (msgl$,msg2$,"Retry","CANCEL", 2,answer%)*
IF answer%=0 THEN 'CANCEL was selected.*
CLOSE #1*
MENU ON:MENU 1,0#1:MENU 2,0,1*
MENU 3,0,1:MENU 4,0,1*
GOSUB ScreenSetup*
RESUME MainLoop*
ELSE*
CLOSE #1*
ON ERROR GOTO ErrorTrap*
RESUME*
END IF*
*
SUB Requester (msgl$,msg2?,bl$,b2$,hilite%,answer%) STATIC*
1 Requester window subprogram version 3.4.*
SHARED scrid 'Global variable for SCREEN ID.*
IF scrid<l OR scrid>4 THEN scrid=-l 'Default to Workbench.*
WINDOW 3,"Program Request",(0,0)-(311,45),16,scrid*
maxwidth=INT(WINDOW(2)/8) 'Truncate prompts if too long...*
PRINT LEFT?(msgl$,maxwidth):PRINT LEFT$(msg2$,maxwidth)*
bl$=LEFT§(bl§,12):b2?=LEFT$(b2§,12) 'Truncate buttons.*
bsizel=(LEN(bl$)+2)*10:bsize2=(LEN(b2$)+2)*10 'Button size.*
xl=(312-(bsizel+bsize2))/3 'Calculate button positions...*
x2=xl+bsizel:x3=xl+x2:x4=x3+bsize2*
'Draw buttons:*
LINE (xl,20)-(x2,38),2,b:LINE (x3,20)-(x4,38),2,b*
IF hilite%=l THEN LINE (xl+2,22)-(x2-2,36),3,b*
IF hilite%=2 THEN LINE (x3+2,22)-(x4-2,36),3,b*
LOCATE 4,1:PRINT PTAB(xl+10);bl$;*
PRINT PTAB(x3+10);b2$*
reqloop: 'Loop which acts on mouse clicks...*
WHILE MOUSE(0)=0:WEND:ml=MOUSE(l):m2=MOUSE(2)*
IF ml>xl T^ND ml<x2 AND m2>20 AND m2<38 THEN*
answer%=l 'Left button was selected.*
LINE (xl,20)-(x2,38),l,bf 'Flash left button.*
ELSEIF ml>x3 AND ml<x4 AND m2>20 AND m2<38 THEN*
answer%=0 'Right button was selected.*
LINE (x3,20)-(x4,38),l,bf 'Flash right button.*
ELSE*
GOTO reqloop 'Neither button selected; repeat loop.*
END IF*
WHILE MOUSE(0)<>0:WEND:WINDOW CLOSE 3*
END SUB*
Program 5-2. ToneDialer
' *** TONEDIALER ****
*
Initialize:*
DIM touchtone(11,2) ' Array for tone values.*
'Define tones for keys (frequencies in Hertz);*
'official Touch-Tone system uses two tones per digit:*
touchtone(0,l)=941:touchtone(0,2)=1336 ' 0*
touchtone(1,1)=697:touchtone(1,2)=1209 ' 1*
touchtone(2,1)=697:touchtone(2,2)=1336 ' 2*
touchtone(3,l)=697:touchtone(3,2)=1477 ' 3*
touchtone(4,1)=770:touchtone(4,2)=1209 ' 4*
touchtone(5,1)=770:touchtone(5,2)=1336 ' 5*
touchtone(6,1)=770:touchtone(6,2)=1477 ' 6*
touchtone(7,1)=852:touchtone(7,2)=1209 • 7*
touchtone(8,1)=852:touchtone(8,2)=1336 ' 8*
touchtone(9,1)=852:touchtone(9,2)=1477 ' 9*
touchtone(10,1)=941:touchtone(10,2)=1209 ' **
touchtone(ll,l)=941:touchtone(ll,2)=1477 ' #*
GetNumber:*
WINDOW 1,"ToneDialer",(300,140)-(620,185),22*
WIDTH 30*
ReEnter:*
CLS:PRINT "Enter number to dial:"*
PRINT STRING?(21,"-")*
LINE INPUT ">> ";number?*
IF number?="" THEN ReEnter*
A
ToneDial:*
FOR n=l TO LEN(number?)*
'Check for * and # keys:*
IF MID?(number?,n,l)="*" THEN number=10:GOTO PlayTone*
IF MID?(number?,n,l)="#" THEN number=ll:GOTO PlayTone*
'Pause two seconds for comma:*
IF MID?(number?,n,l)="," THEN*
pause&=TIMER*
WHILE TIMER<pause&+2:WEND*
END IF*
'Ignore all nondigit characters:*
IF ASC(MID?(number?,n,l))<48 THEN Nextnumber*
IF ASC(MID?(number?,n,l))>57 THEN Nextnumber*
'Convert input to proper digit:*
number=VAL(MID?(number?,n,l)) 'Digits 0 to 9*
PlayTone:*
SOUND WAIT 'Makes sure tones are synchronized...*
SOUND touchtone(number,1),5,,0 'Lo tone, left channel.*
SOUND touchtone(number,2),5,,2 'Hi tone, left channel.*
SOUND touchtone(number,1),5,,1 'Lo tone, right channel.*
SOUND touchtone(number,2),5,,3 'Hi tone, right channel.*
SOUND RESUME*
FOR delay=l TO 200:NEXT 'Short delay between tones.*
Nextnumber:*
NEXT n*
GOTO ReEnter 'Do it again...*