Classic Computer Magazine Archive START VOL. 3 NO. 12 / JULY 1989



ON DISK!

Programming In BASIC

Sound Wave Stylist

BY SAL GUTIERREZ



Create sound effects in real-time, then let the Stylist write the BASIC code for you! File STYLIST.ARC on your START disk.

The ST is capable of making some pretty good sound effects. You and I know it, because we've heard them in commercial programs. The problem is that there is very little documentation about how to tap this almost hidden resource. You can generate sound using the SOUND and WAVE commands, but it's hard to get just the right effect. I developed the Sound Wave Stylist as a graphic sound-designing tool that will generate BASIC code compatible with GFA BASIC versions 2 and 3, HiSoft BASIC and HiSoft BASIC Professional.


soundwave1.jpg
Figure 1. The wave forms (envelopes) available for the WAVE com-
mand. The numbers are the values you need to enter in the WAVE
command to use the corresponding wave form.

The SOUND and WAVE Commands

The SOUND and WAVE commands used to control sound output are common to GFA, HiSoft and ST BASIC. The syntax of the commands is:

SOUND voice, volume, pitch, octave [,duration]

and

WAVE voice, envelope, form, length, duration

By itself, the SOUND command manipulates voice, volume, pitch, octave and time duration before the next command is executed. There are three voices available from the ST's built-in Yamaha sound chip. Volume is set with an integer value between 0 and 15 (0 turns the volume off and 15 turns it up full blast). Pitch can be any integer value between 1 and 12, 1 being the lowest frequency selectable within the octave and 12 being the highest. The octave value can be any integer value between 1 and 8, with 1 being the lowest. The duration is an integer value that specifies the length of time (in 1/50ths of a second) to play the sound.

The WAVE command does not produce any sound; rather, it defines the parameters for the SOUND command. Its parameters are voice, envelope, form, length and duration. The wave voice determines which of the three sound voices will be active and in what combinations.

Wave Voice1--Sound voice 1
2--Sound voice 2
4--Sound voice 3
8--Noise on channel 1
16--Noise on channel 2
32--Noise on channel 3

Notice that you can produce noise on each of three channels. Noise takes the shape of the form selected and is played regardless of what pitch or octave values are set in its corresponding sound voice. Selecting noise on a particular channel does not mean that you can't select the normal sound voice on the same channel at the same time. To establish your wave-voice value, determine which sound voices you want to be heard, and any noise, and then add up the corresponding voice values. For example, to hear sound voices 1 and 2 plus noise on channel 1, add 1 for sound voice 1, 2 for sound voice 2, and 8 for noise on channel 1. The total, 11, is the wave-voice value.

The envelope parameter reflects which of the three sound voices will be directly shaped by the chosen wave form.

Wave Envelope 1-Sound voice 1
2-Sound voice 2
4-Sound voice 3

The wave envelope, like the wave voice, can include more than one voice by adding together the corresponding sound-voice values (1, 2 or 4). Notice that the sound voices are the only ones available here; the noise channels are automatically set to output by their selection in the wave-voice parameter. Any sound voice that is active, but not set to play noise in this value, will play pure tone.

The form value is that of the shape of the wave. (See Figure 1.) Remember that this selection will only affect the sound voices set in the wave envelope parameter. The length value tells the WAVE command how many units of time (in 1/8,000ths of a second) to use to complete one full cycle of the wave form. For example, if form 8 has been selected with a length of 16,000, it will take two seconds to complete one cycle to linearly rise from a zero volume level to full volume and back to zero volume again.

soundwave2.jpg
Figure 2. Sound Wave Stylist is a fun and easy-to-use tool for exper-
imenting with the ST's sound chip. If you're a programmer, Sound
Wave Stylist can even generate sound code files that you can load
into your own HiSoft, GFA or ST BASIC programs.

The function of the duration value for the WAVE command is identical to the duration value in the SOUND command; it determines how long to play the sound before execution of the next command.

Although becoming familiar with these commands can be a frustrating experience at first, they will let you create some awesome sound effects. The bottom line is that if you want pure sound only, simply use the SOUND command for the three voices and disregard the WAVE command. However, you want to use the WAVE command, establish the pitch and octaves for the sound voices using the SOUND command first, leaving the durations set at zero. Then use the WAVE command to set active voices, envelope, form, length (of form cycle) and duration of play.


Making It Sound Right

Unless you know the exact parameters required for any particular sound effect, you normally must endure a lot of hit-and-miss programming. My Sound Wave Stylist displays all of the controls needed to alter parameters in SOUND and WAVE commands in real-time--while you hear the sound. UnARC STYLIST.ARC, following the Disk Instructions elsewhere in this issue. Double-click on STYLIST.PRG in medium or high resolution to bring up the screen shown in Figure 2.

On the left side of the screen are the command blocks for the three sound voices and the wave function. Click the left mouse button in a box containing an arrow to change all the values. You can't alter the pitch and octave values for the SOUND commands unless the volume is set to a value greater than 0 for that channel. Setting the volume value to 0 sets pitch and octave values to 0 automatically. If the voice parameter in the WAVE command block is zero, sounds will be played as pure tones regardless of any other values.

In the upper right part of the screen are the FORMS, VOICE and ENVELOPE boxes. They not only serve as a reference to the possible wave configurations, but you can also use them to set the wave-command block directly. Simply left-click on the desired form, voice or envelope (or click on a box again to deselect it). The appropriate parameter in the command block will be updated with the new value. Notice that since only one form can be specified at a time, any previously highlighted form will be deselected in favor of the new. Voice and envelope parameters, on the other hand, can be selected in any combination.

At the lower right part of the screen is, essentially, a tape recorder/player that lets you record the contents of the command blocks currently on the screen for subsequent playback. You an also save your recorded sounds to disk in ASCII files that you can merge into your BASIC programs.


The Tape-Recorder Controls

Tape Counter and Strip The strip represents the 64 screens (0-63) of command-block information that are available for recording. As each screen is recorded, the strip will highlight the next empty slot and increment the tape counter by one.

Direct PLAY When selected, this box will highlight and the program will play any sound on the screen at that time. At this point you can change any parameter and hear the result immediately. A duration value in either the SOUND or WAVE command block is ignored in this mode. Sounds are played in this order Sound 1, Sound 2, Sound 3 then Wave. Unless you have a voice parameter other than 0 in the WAVE command block, you will only hear the last sound with a volume greater than 0. CIick on STOP to exit this mode.

Current PLAY Click here to highlight the Current box and play the SOUND and WAVE command blocks. Unlike Direct PLAY the duration values are taken into account here, so the command will automatically end at the times specified by the durations. This is exactly what the sequence will sound like in your program.

PLAY Click here to highlight the PLAY box and play back the prerecorded screens in sequence. The tape strip, counter and command-block data are updated. The program stops playing when either the end of the recorded tape is reached or you click on the STOP button.

REWIND/FAST FORWARD These options highlight the rewind or fastforward button and rewind or advance the tape. The tape strip, counter and command block are updated. This command ends either automatically at the beginning or end of the tape or when you click on the STOP button. To move to a specific counter number, hold the left mouse down while and select rewind or fast forward, then move the mouse to the STOP button when you reach the desired number.

STOP Used to end PLAY, Direct PLAY, REWIND and FAST FORWARD.

REC Records current command-block parameters to tape. The tape strip and counter are updated to the next available slot. If you click the right mouse button while holding the left button down, the current command-block parameters will be copied to next screen. This is a handy option when you're recording a sequence that is similar in each frame. If the right mouse button is not pressed, all command blocks are zeroed. This command ends when you release the left mouse button.

ERA This command will erase the tape from the current tape counter/strip position to the end of tape. An alert box verifies your choice. ERA does not clear the current command blocks.

LOAD Any previously saved recorded sequence can be loaded by this command. A file-selector box will prompt for a filename with an .LST extension. Tape strip and counter will reset to the beginning of the tape. The command blocks will reflect the parameter of the first screen recorded.

SAVE A file-selector box will prompt for a filename for the current recorded tape. A filename extender of .LST will be appended to the filename automatically if none is specified. You can load files into this program at any time or use them in your BASIC programs. You can load Stylist files directly into HiSoft BASIC; load them into GFA BASIC using the Merge command. The command syntax of SOUND and WAVE works with ST BASIC programs; however, you will need to add line numbers to the beginning of each line before loading the file. The order in which the commands will appear in the listing will be: Sound 1, Sound 2, Sound 3 then Wave.


Make a Lot of Noise

I hope this program will help you develop the sound effects that will best complement your programs. Any comments or suggestions to enhance this program are invited. I believe that all programmers who are trying to put their STs to the best possible use should be able to do so as effortlessly as possible.

Sal Gutierrez lives in Valdosta, Georgia. He wrote the Morse-code aid, Dah-Ditter, in the February 1989 issue of START.