16 BIT SOUND POWER
How the pros enhance Atari musicby JERRY WHITE
Beef up your Atari music from BASIC. Learn how to program 16-bit dual-voice sound. You 'll get a richly melodic seven octaves, instead of the thinner-sounding four octaves you'd bear otherwise. This short BASIC program works on any Atari computer of all memory sizes, with disk or cassette.
If you have experimented with SOUND commands in Atari BASIC, you probably noticed that some of the higher notes seem a bit flat. You may have also found that your lowest note is the B generated by SOUND 0,255,10,8.
Using SOUND commands with a distortion value of 10 for clear sound, you have a range of just over four octaves. If you'd like to fine-tune your music and extend that range to seven octaves, this tutorial will tell you how.
The SOUND 16 program will demonstrate what is called 16-bit sound. It is based on using two combined voices to create one sound. Only two sounds can be produced at once, but the frequency of each pitch will be more accurate and much deeper bass notes can be generated.
Type in Listing 1, SOUND16.BAS, check it with TYPO II and SAVE a copy before you RUN it.
This listing uses an assembly language subroutine to turn 16-bit sounds on and off. This assembler routine appears in the BASIC program as the DATA statements starting at line 20010. The FOR/NEXT loop at line 130 reads this data and stores our subroutine in the string S16$.
This demonstration program shows how the desired frequency and volume for one or two voices can be passed to the subroutine by using BASIC's USR function. Note that the SOUND and POKE commands found in line 150 must be executed before your first USR call.
The BASIC program reads frequency data into an array called FREQ. This array stores 12 frequencies for each of seven octaves. Octave one contains the highest note frequencies, while octave seven contains the lowest bass notes.
Each octave begins with C as its lowest note (pitch 12), and ends with B as its highest note pitch 1). Middle C (SOUND 0,121,10,8) is frequency 3414 or FREQ(4,12) in our array. The next highest note, C#, is FREQ(4,11).
The next lowest note, B, is FREQ(5,1).
The program uses a countdown timer to clock delays. When you POKE a number from 1 to 255 into location 540, it will be decremented every 1/60th of a second. 1/60th of a second is called a "jiffy." Thus, if you set the variable WAIT 60, then go to the subroutine beginning at line 480, you will return in one second.
Octave, pitch and note will be displayed on the screen as the program cycles through all frequencies. Next, the double 16-bit sound option will be used to demonstrate the use of consecutive octaves. Finally, a short tune is played just before the program ends.
Antic Contributing Editor Jerry White is a leading light of Atari programming and founded PAPIE, the Professional Atari Programmers Information Exchange.
Listing: SOUND16.BAS Download