Classic Computer Magazine Archive ANTIC VOL. 8, NO. 7 / DECEMBER 1989

Antic Sound Creator

By Jeffery Summers, MD

You'll see why a violin sounds different from a clarinet.

Sound waves move in strange and mysterious ways. If you ever wondered what makes a violin sound different from a clarinet, Antic Sound Creator will help you explore the wonders of harmonics. This simple, easy-to-use BASIC program works on 8-bit Atari computers with at least 48K memory and disk drive.

Sitting on a park lawn listening to a band playing a free concert on a warm springtime day, I started thinking about what makes different instruments sound different. A trumpet and a flute, for example, may play the same note, yet they sound different.

The differences in sound character that distinguish one instrument from another are due to the presence of "harmonics" or overtones. To understand what these are and why they are important, think of a jumprope. It is easy to make a jumprope move up and down along its entire length. This we will call the primary wave.

With a little more energy and a flick of the wrist, it is possible for you to get the rope to vibrate on two halves - when one half of the rope is up, the other half is down, and vice versa. The center of the rope doesn't move in this situation. This we will call the secondary wave. If you are Hulk Hogan you can probably get the rope to further split into thirds or quarters, but it gets a lot more difficult.

Anyway, if you think of the primary wave as your first harmonic, then the secondary wave as the second harmonic and so on, you get the idea of what a harmonic is. When a violin string vibrates, the primary wave is produced by the entire length of string vibrating.

However, to a lesser extent the string also vibrates in halves, thirds, quarters, and so on. If you look closely at a vibrating violin string you can actually see points on the string where the vibrations decrease. (The harmonic point in the center of the string is usually the easiest to spot.) It is the relative contribution of these overtones that make the violin sound like a violin. A flute, playing the same note, will have different relative amounts of the overtones or harmonics and therefore it sounds different from the violin.

To demonstrate this concept I wrote the Antic Sound Creator. This program allows you to create a sound wave either by drawing the wave free-hand, or by adding overtones together, or by combining both methods. To use the program, type in Listing 1, check it with Typo II and be sure to SAVE a copy before you RUN it.

When the program starts, an x-axis and a y-axis are drawn in orange. Then a flat wave is drawn in green. The wave is flat because we haven't designed anything yet. A menu appears at the bottom of the screen. The options are to Add a Harmonic, Load and Save waves, Clear the wave, Quantize, Play, Draw, and Exit.

Adding a harmonic will add a sine wave to the current wave. You are first asked which harmonic you wish added. A pure sine wave whose length would fill the pattern would be harmonic number 1. A sine wave that would repeat once across the screen (two sine waves) would be 2, and so on. For our example, enter 1.

You are next asked for a scaling factor. This will govern the amplitude (loudness) of the wave being added. The value of the scaling factor can range from zero to a maximum of 1. Values above 1 will be cut off. It is difficult to add large-scaled harmonics together without such "clipping" (more on this later). Four our example, enter .3.

The new wave is now drawn on the screen. To hear what this pure sine wave sounds like, press [P] to play the wave. You are then asked for a delay factor from 1 to 10. The number you enter will regulate the pitch of the tone. The values from 1 to 10 and their approximate pitches (very approximate in some cases) are shown in Figure 1. For our example, enter 3 for the delay. After a moment, the screen clears and you will hear the sound through your speaker.
Antic Sound Creator

Press any key to stop the sound and return to your screen. Next let's add an overtone. Type [A] to add another harmonic, and when you are asked which harmonic you wish to add, type 2. For the scale, enter .3 again. The second wave is added to the first mathematically, and the resulting combined wave will be drawn. Press [P] to hear the new wave. See and hear the difference? Not much, with only one harmonic added, but you'll see more changes later.

Delay Value Note
1 E above high C
2 B above middle C
3 A flat above middle C
4 F above middle C
5 E flat above middle C
6 C sharp (middle C)
7 B below middle C
8 A below middle C
9 G below middle C
10 F sharp below middle C

Now let's draw in a few changes to our wave. When you press [D], a cursor appears toward the bottom of the screen. The cursor is under the column you are working on. You may use the joystick or the [ARROW KEYS] (holding the [CONTROL] key is not necessary) to move the cursor sideways from column to column and up/down to change values. To exit the Draw mode, simply move the cursor all the way to the right, off the wave.

Using Draw mode, you can change the shape of the wave as you wish and hear the results. You can draw waves that would be nearly impossible to create from the addition of overtones, such as square waves and sawtooth patterns. To exit the draw mode simply move the cursor off the wave to the right.

The POKEY chip, which actually produces the sound we hear, only allows sixteen different values on the vertical y-axis of our graph. To get the most accuracy possible, the values for the wave are stored in the usual Atari floating point format. But when POKEY actually plays the wave it must be scale to the range 0-15. Thus, if you make a very minor change to the wave on the screen, it may make no change at all to what you hear due to the limitations imposed by POKEY.

TO see exactly what POKEY will play, you may press [Q] to quantize the wave. This converts the current wave into the actual wave POKEY will play. It usually isn't as pretty, and you can't un-quantize back to your original wave. So make sure you save your wave before you quantize, if you think you want to keep it and later modify it.

Pressing [S] allows you to save the wave you have been working on. You are prompted for a filename. If you don't enter a device, D: is assumed. The program will then save your data. Later, you may re-enter your data by using the [L] command and entering the same filename.

For the technically-minded who wish to create sounds not easily created by the addition on harmonics nor by freehand drawing, it would be easy to create a file compatible with this program. The files simply consist of a list of 100 numbers ranging from zero to sixteen, separated by [RETURN]s.

Thus, you can write a quick program to generate the file so you can graph and play such waves as sin(x)(sin(4x)).

What happens when you add too many harmonics together and exceed the legal range of values of the program?

To see, use [C] to clear the current wave. Now press [A] to add a harmonic, enter a 1 for the harmonic, then enter .4. Play this with a delay of 5. The sound should be a nice pure sine wave.

Clear again and create a first harmonic wave with a scale of .8. Play this and aside from an increase in loudness the sound should be the same. Clear again and create a first harmonic wave with a scale of 1.5. Look at the wave on the screen. See how it looks clipped off on the top and bottom?

Now play this also with a a delay of 5. The difference you hear is due to "clipping". Now when you buy stereo equipment you will know what the salesman means when he talks about speakers clipping when a certain volume is reached. Pressing [E] clears the screen and exits the program.

Now that you know how the program works, let's try some different sounds. If you have a wave on the screen, press [C] to clear it. Press [A] to add a harmonic, and use the first harmonic with a scaling of .3. Next add harmonic number 2 with the same scaling of .3. Continue adding harmonics with values of 4, 8, and 16, all with scalings of .3.

Now play the wave. It sounds to me like an organ. Save this if you like, then use [C] to clear the wave. Now, add harmonics with values of 1, 3, 5, 7, and 9 all with scaling values of .3.

Play this, also with a delay of 5. It may not be Benny Goodman, but to me it sounds like a clarinet.

A physician from Rochester, NY, Jeffery Summers is a frequent contributor to Antic and an 8-bit MIDI musician. His review of MIDIMAX appeared in the May 1989 Antic. His handy text-locating program Super Locator ran in the June 1989 issue.

Listing 1: SOCREATE.BAS Download

On Disk: CLARINET.SND Download
, ORGAN.SND Download