Make a musical peripheral for your ATARIby VERN MASTEL
This article shows you how to build and connect a true piano-type keyboard that you can use with your ATARI computer as a simple music synthesizer. Included in the article is the software that allows you to play music.
The method is very simple from a hardware standpoint, requiring only some signal diodes and microswitches. The software will run on any ATARI computer from 16K on up with no modifications. Best of all, the program uses only BASIC -- no machine language subroutines are used.
To begin, a discussion of the ATARI parallel data bus and joystick mechanics is necessary. "Beg pardon," you say, "the ATARI doesn't have a parallel data bus." Well, strictly speaking, it doesn't; but what it does have comes awfully close in this application. The ATARI joystick is a wonderfully simple device, consisting of only five switches and a housing. Four switches sense the major positions, and the fifth one senses the trigger (see Figures 1 and 2). Moving the stick in any given direction never closes more than two of the four switches at one time. Take a look at Program 1. Most will recognize it as a simple program to read the joystick position and print out the number corresponding to it.
10 A = STICK(0):REM CAN BE ANY OF THE FOUR STICKS
20 PRINT A
30 GOTO 10
Note how the numbers run 5, 6, 7, 9, 10, 11, 13, 14, 15. What, happened to 0, 1, 2, 3, 4, 8, 12? Now take the top off the joystick, RUN Program 1 and press two or more switches at once. Presto, the missing numbers appear! For a diagram of the switch patterns and the corresponding number returned by the STICK command, see Figure 3. What all of this boils down to is that each controller port on the ATARI can be treated as a four-bit parallel input port. Four bits are half of a byte and can be used to count in base 16. By selectively grounding combinations of the four input pins, the numbers from zero to 35 will be generated. This is the key to our Simple Synthesizer.
First, a keyboard is required. It can be anything from a dime store toy piano to a grand piano as long as it has the righ complement of keys. I got mine from a junked Wurlitzer organ at a local music store for only $20. One octave (C through C) is all that is needed, so you should not have any problem finding something to suit. One octave is only 13 notes and there are16 combinations available on one input port. If the note values are stored in a matrix in the same sequence they follow on the keyboard, then pressing a key will play the associated value stored in the matrix. For example,
10 DIM M(3):M(1)=243:M(2)= 217: M(3)=193
20 FOR X=1 TO 3:SOUND 0,M(X),10,10
30 FOR D=1 TO 100:NEXT D:REM DELAY
40 NEXT X:SOUND 0,0,0,0
This program will play three notes, C, D and E, in succession. The SOUND command does not care where the arithmetic value which specifies the pitch comes from, so what happens if a joystick is used to generate the values? Try Program 3 and find out.
10 DIM M(13)
20 FOR X=1 TO 13
30 READ A
40 M(X) = A
50 NEXT X:REM GET THE NEXT VALUE
60 A = STICK(0):IF A = 0 THEN 60
70 SOUND 0,M(A)-4,10,10
80 GOTO 60
90 DATA 243,230,217,204,193,182
100 DATA 173,162,153,144,136
110 DATA 128,121
What this program does is to put 13 note values (one octave) into matrix M and then use the joystick to change the pitch. Are you beginning to get the idea of how the Simple Synthesizer will work?
One problem remains to be tackled. To generate each note with a keypress on a keyboard at least two switches would be needed if you counted from three to 15. If you count from one to 13 then at least three would be needed. The problem comes when you try to mount three microswitches under one key -- there simply isn't enough room. The solution lies in the use of a diode matrix as shown in Figure 4. Using this, only one switch is needed to handle each number from one to 13. The diodes pass DC current in only one direction and thus isolate each port pin from the others.
One additional ATARI hardware feature used with the Simple Synthesizer is the game paddles. Each port handles two paddles. For this application, two ports are used. The reason for this is to allow individual control of the volume of each voice of the Synthesizer. Normally, the resistance value of the potentiometers used in the paddles is one megohm (1,000,000 ohms). This value gives a count range of zero to 228. To use the paddles to control the volume, a range of only zero to 10 or 12 is needed. If you are using more than three voices, the highest recommended value for volume is eight. If the sum of all volumes exceeds 32, sound is distorted. You could use a one-meg pot and divide the count to limit it to 12, but that wastes time in the program and upsets the smooth operation of the notes. The solution is to use a 10K pot (10,000 ohms). This gives a working range of zero to about seven, which is just right.
Now that the hardware has been covered, it is time tor the software. Program 4 is the listing of the program which allows you to use the keyboard. Sound generation is handled by three separate routines -- one each for multiple-voice mode, chord mode and piano mode. The modes are what the names imply. In the multiple-voice mode each voice is active, its level or volume determined by the setting of the associated paddle pot. In the chord mode, pressing a key generates the major chord of that key. For example, pressing C also generates the notes E and G.
It is interesting to note that Atari says this cannot be done well from BASIC because BASIC is too slow. As you will see when you RUN the program it is not only possible, it works very well.
The piano mode is the most interesting of the group because it involves dynamics which really do strain BASIC to the limit. When in this mode, a key which is pressed and held will decay to zero volume and not play again till the key is released and pressed again. If the key is released before the decay is finished, the note will be cut off (this is similar to what you would encounter with the rest pedal on a piano). If one note is pressed and then another, before the first has decayed, the second note will then sound and be allowed to decay. The rate of decay is determined by the size of the D loop in line 60 of the program. A larger value will take longer to decay; a smaller value will yield a shorter decay.
In all modes, the frequencies of all of the notes are stored in matrixes (L)ow, (M)edium and (H)igh. These matrixes are automatically loaded with the correct values at the time of mode selection. You will notice that the screen is blank when a play mode is selected. This was done after I noticed that some notes would be missed if I played-fast enough with the screen on. Turning off the screen allows the Operating System to read the ports more often and thus keeps the notes from getting lost.
Rather than going into a long line-by-line description of the program, I chose to comment it heavily. These REMarks are strictly for illustration and should be deleted from the program after you have checked it with TYPO. If REM statements are not removed, the piano voice may be adversely affected. This program is by no means the final word in synthesizers, but it is a springboard from which you can proceed.
Use of the program is very simple. When RUN, a menu of six choices is displayed:
1) Multiple voices
2) 1st Octave chords
3) 2nd Octave chords
4) Piano Octave 1
5) Piano Octave 2
6) Piano Octave 3
Pressing the number of the desired mode activates the music keyboard. The screen will go blank at the same time. Pressing any key on the computer keyboard will restore the menu. In the first three modes you can control the volume of the individual voices with the pots connected to the paddle inputs. In the piano mode, the volume is fixed.
Lastly, to all of the musicians out there, please don't attack me over the accuracy of the pitch of all of the notes. The numbers in the program are from the official Atari pitch chart. I know if they aren't right on the button but remember this is done for fun, not for the New York Philharmonic.
NOTE: This project should not be undertaken by beginners. You should be fairly comfortable with assembling and wiring electronic circuits before attempting to wire a keyboard. It is not within the scope of this article to provide basic information on wiring circuits.
Vern Mastel is the manager of a Team Electronics store in Bismarck, ND, where he sells computers, including the ATARI, and related equipment. His favorite pastime is writing programs.
Listing: SMPSYNTH.BAS Download