Antic Sound Creator

Type
Sound
Category
Waveform designer and player (harmonics demo)
Author
Jeffrey Summers
Published in
Antic, December 1989/January 1990 (Vol. 8, No. 7)
Year
1989
Language
Atari BASIC
Requirements
48K RAM, Atari BASIC, disk drive (to save waves); joystick optional

About the program

Sitting at a free band concert in the park, Jeffrey Summers, MD, began wondering why a trumpet and a flute playing the same note sound different. The answer is harmonics. A vibrating string or air column vibrates as a whole, but also in halves, thirds, quarters and so on, and the mix of those overtones gives each instrument its character. Summers compared it to a jump rope. Anyone can make the whole rope swing; with a flick of the wrist you can make it swing in two halves; and "if you are Hulk Hogan" you might manage thirds or quarters.

Antic Sound Creator, from the December 1989/January 1990 issue, lets you hear the idea. You design one cycle of a wave, either by adding sine-wave harmonics or by drawing it point by point, and the Atari plays it. Square and sawtooth waves that would be hard to build from harmonics are easy to draw.

Typing it in

Plain BASIC, with a 57-byte machine-language player in the DATA of lines 11000–11050. Check those numbers carefully, because the routine turns off the screen and interrupts while it plays, and a wrong byte will hang the machine. The menu letters in lines 1020–1025 are inverse ({inv}…{/inv}, typed with the Atari key). The disk version has no TYPO II codes. The program uses DEG, so the SIN() in line 2020 works in degrees.

How to use it

RUN it. Orange axes and a flat green wave appear, with a menu below:

  • A: add a harmonic. Give the harmonic number (1 = one cycle across the graph, 2 = two, and so on) and a scale factor from 0 to 1. Summers' walk-through used harmonic 1 at .3, then harmonic 2 at .3. Values that go off the top or bottom are clipped.
  • P: play. Enter a delay from 1 to 10, which sets the pitch: from roughly E above high C at 1 down to about F sharp below middle C at 10. The screen goes blank while the wave plays; press any key to stop.
  • D: draw. Move the cursor under the graph with the joystick or the arrow keys (no CTRL needed), raise and lower each point, and move off the right-hand end to finish.
  • Q: quantize. Snap the wave to the 16 levels POKEY can really produce, so you can see what you're hearing. This can't be undone.
  • S / L: save or load a wave. D: is assumed if you give no device. C clears and E exits.

Summers noted that wave files are just 100 numbers, one per line, so you can write a short BASIC program to generate unusual waves mathematically and load them in.

How it works

  • POKEY as a 4-bit DAC. Writing a value of 16 plus a number from 0 to 15 to AUDC1 sets channel 1's volume-only bit. The speaker then simply outputs that volume level, with no tone generator involved. Change the level fast enough and you can play any waveform. Line 3020 converts the 100 wave values into a string of CHR$(16+level) bytes for the player.
  • The player (DATA 11000–11050) takes a delay and the string's address from USR. It clears AUDCTL, turns off interrupts (NMIEN) and screen DMA so nothing upsets the timing, and then loops: send the next byte to AUDC1 (53761), count down the delay, repeat for 100 bytes, and start again until location 764 shows a keypress. Back in BASIC, line 3030 turns the screen and interrupts on again.
  • Why the pitch comes from a delay. One pass through the 100 samples is one cycle of the note, so a longer delay per sample gives a longer cycle and a lower note.
  • Adding harmonics (line 2020) is plain arithmetic: each of the 100 points gets SCALE*SIN(3.6*MULT*I)*7 added to it, since 3.6 degrees × 100 points makes one full circle. Starting from the midpoint 8, the result is clipped to 0–15.

Variations to try

Build a square wave in draw mode and compare it with harmonics 1, 3 and 5 added at falling scales: odd harmonics are what make a square wave. Try harmonic 1 plus a little of harmonic 2 for something reedier, then quantize and listen to how little changes.

Listing

10 REM SOUND CREATOR
20 REM BY JEFFREY SUMMERS
30 REM (C) 1989 ANTIC PUBLISHING, INC
99 GOTO 10000
100 COLOR 1:PLOT 10,30:DRAWTO 111,30:COLOR 2:FOR I=1 TO 100:PLOT 10+I,62-4*WAVE(I):NEXT I:RETURN
1000 GRAPHICS 7:SETCOLOR 4,0,13:COLOR 1
1010 PLOT 10,0:DRAWTO 10,60:PLOT 10,30:DRAWTO 110,30
1015 GOSUB 100
1020 PRINT "{inv}A{/inv}dd Harmonic  {inv}P{/inv}lay wave  {inv}D{/inv}raw wave"
1025 PRINT "{inv}S{/inv}ave wave   {inv}L{/inv}oad wave  {inv}C{/inv}lear wave":PRINT "{inv}Q{/inv}uantize   {inv}E{/inv}xit"
1030 OPEN #5,4,0,"K:":GET #5,X:CLOSE #5
1040 IF X=65 THEN 2000
1050 IF X=80 THEN 3000
1060 IF X=68 THEN 4000
1070 IF X=83 THEN 5000
1080 IF X=76 THEN 6000
1085 IF X=67 THEN 7000
1086 IF X=81 THEN 8000
1087 IF X=69 THEN GRAPHICS 0:GOTO 12000
1090 GOTO 1020
2000 TRAP 2000:PRINT "Harmonic multiple: ";:INPUT #1,MULT
2010 TRAP 2010:PRINT "Scale factor: ";:INPUT #1,SCALE:TRAP 40000
2020 FOR I=1 TO 100:COLOR 0:PLOT 10+I,62-4*WAVE(I):WAVE(I)=WAVE(I)+SCALE*(SIN(3.6*MULT*I)*7)
2025 IF WAVE(I)>15 THEN WAVE(I)=15
2026 IF WAVE(I)<0 THEN WAVE(I)=0
2030 COLOR 1:PLOT 10+I,30:COLOR 2:PLOT 10+I,62-4*WAVE(I):NEXT I
2040 GOTO 1020
3000 TRAP 3000:PRINT "Frequency (delay): ";:INPUT #1,DELAY
3010 TRAP 40000
3020 FOR I=1 TO 100:WAVE$(I)=CHR$(16+WAVE(I)):NEXT I:D=USR(ADR(PLAY$),DELAY,ADR(WAVE$))
3030 POKE 54272,34:POKE 54286,64
3040 GOTO 1020
4000 I=1:OPEN #5,4,0,"K:"
4010 COLOR 1:PLOT 10+I,70:DRAWTO 10+I,75
4020 POKE 764,255
4030 IF STICK(0)<>15 THEN 4200
4040 IF PEEK(764)=255 THEN 4030
4050 GET #5,X:IF (X<>42) AND (X<>43) AND (X<>61) AND (X<>45) THEN POKE 764,255:GOTO 4030
4060 IF X=42 THEN COLOR 0:PLOT 10+I,70:DRAWTO 10+I,75:I=I+1:IF I<=100 THEN 4010
4065 IF X=42 THEN CLOSE #5:GOTO 1020
4070 IF X=43 THEN COLOR 0:PLOT 10+I,70:DRAWTO 10+I,75:I=I-1:IF I<1 THEN I=1
4075 IF X=43 THEN 4010
4080 IF X=45 THEN COLOR 0+(WAVE(I)=0):PLOT 10+I,62-4*WAVE(I):COLOR 2:WAVE(I)=WAVE(I)+0.25
4081 IF WAVE(I)>15 THEN WAVE(I)=15
4082 IF X=45 THEN PLOT 10+I,62-4*WAVE(I):GOTO 4010
4090 COLOR 0+(WAVE(I)=0):PLOT 10+I,62-4*WAVE(I):COLOR 2:WAVE(I)=WAVE(I)-0.25:IF WAVE(I)<0 THEN WAVE(I)=0
4095 PLOT 10+I,62-4*WAVE(I):GOTO 4010
4200 X=STICK(0)
4210 IF X=7 THEN COLOR 0:PLOT 10+I,70:DRAWTO 10+I,75:I=I+1:IF I<=100 THEN 4010
4215 IF X=7 THEN CLOSE #5:GOTO 1020
4220 IF X=11 THEN COLOR 0:PLOT 10+I,70:DRAWTO 10+I,75:I=I-1:IF I<1 THEN I=1
4225 IF X=11 THEN 4010
4230 IF X=14 THEN COLOR 0+(WAVE(I)=0):PLOT 10+I,62-4*WAVE(I):COLOR 2:WAVE(I)=WAVE(I)+0.25
4231 IF WAVE(I)>15 THEN WAVE(I)=15
4235 IF X=14 THEN PLOT 10+I,62-4*WAVE(I):GOTO 4010
4240 IF X=13 THEN COLOR 0+(WAVE(I)=0):PLOT 10+I,62-4*WAVE(I):COLOR 2:WAVE(I)=WAVE(I)-0.25
4241 IF WAVE(I)<0 THEN WAVE(I)=0
4245 PLOT 10+I,62-4*WAVE(I):GOTO 4010
5000 PRINT "Filename: ";:INPUT #1,FILE$
5001 IF FILE$(2,2)<>":" AND FILE$(3,3)<>":" THEN F$=FILE$:FILE$="D:":FILE$(3)=F$
5002 TRAP 5900
5010 OPEN #2,8,0,FILE$:FOR I=1 TO 100:PRINT #2;WAVE(I):NEXT I:CLOSE #2:TRAP 40000:GOTO 1020
5900 PRINT "Error in Save":FOR I=1 TO 100:NEXT I:TRAP 40000:GOTO 1020
6000 PRINT "Filename: ";:INPUT #1,FILE$
6001 IF FILE$(2,2)<>":" AND FILE$(3,3)<>":" THEN F$=FILE$:FILE$="D:":FILE$(3)=F$
6002 TRAP 6900
6010 OPEN #2,4,0,FILE$:FOR I=1 TO 100:INPUT #2;X:WAVE(I)=X:NEXT I:CLOSE #2:GOSUB 100:TRAP 40000:GOTO 1020
6900 PRINT "Error in Load":FOR I=1 TO 100:NEXT I:TRAP 40000:GOTO 1020
7000 COLOR 0:FOR I=1 TO 100:PLOT 10+I,62-4*WAVE(I):WAVE(I)=8:NEXT I:GOSUB 100:GOTO 1020
8000 FOR I=1 TO 100:COLOR 0:PLOT 10+I,62-4*WAVE(I):COLOR 2:WAVE(I)=INT(WAVE(I)):PLOT 10+I,62-4*WAVE(I):NEXT I
8010 GOTO 1020
9040 D=USR(ADR(PLAY$),15,ADR(WAVE$))
9050 POKE 54272,34:POKE 54286,64
10000 DIM WAVE$(100),PLAY$(57),R$(1),WAVE(100),FILE$(20),F$(20)
10010 DEG :FOR I=1 TO 57:READ A:PLAY$(I,I)=CHR$(A):NEXT I
10030 FOR I=1 TO 100:WAVE(I)=8:NEXT I
10040 OPEN #1,4,0,"E:"
10099 GOTO 1000
11000 DATA 104, 104, 104, 133, 212, 104, 133, 215, 104, 133
11010 DATA 214, 169, 0, 141, 8, 210, 141, 14, 212, 141
11020 DATA 0, 212, 141, 47, 2, 160, 0, 177, 214, 141
11030 DATA 1, 210, 166, 212, 202, 224, 0, 208, 251, 200
11040 DATA 192, 100, 208, 239, 172, 252, 2, 192, 255, 240
11050 DATA 230, 169, 34, 141, 47, 2, 96
12000 END

Download

The original program from the Antic disk, to LOAD or ENTER instead of typing it: SOCREATE.BAS.

Credits